Codeforces 711A. Bus to Udayland

题目链接:http://codeforces.com/problemset/problem/711/A

题意:

  有一个公交车有 N 行座位,每行座位又分别有四个座位,其中”1“ 号和”2“号相邻, ”3“号和 ”4“号相邻,中间(”2“号和”3“号)由过道分开.车上 ”O“ 代表空座位, "X"代表有人, "|" 代表过道, 有两个人要乘车, 问是否有座位使得他们两相邻.

代码:

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 const int MAXN = 1000;
 6 const double PI = acos(-1);
 7 char bus[MAXN + 3][13];
 8 
 9 bool check(int li, int ro) {
10     if(bus[li][ro] == 'O' && bus[li][ro + 1] == 'O') {
11         bus[li][ro] = bus[li][ro + 1] = '+';
12         return true;
13     }
14     return false;
15 }
16 
17 int main() {
18     ios_base::sync_with_stdio(0); cin.tie(0);
19     int n; cin >> n;
20     for(int i = 0; i < n; i++) for(int j = 0; j < 5; j++) cin >> bus[i][j];
21     int flag = 0;
22     for(int i = 0; i < n; i++) if( !flag && (check(i, 0) || check(i, 3)) ) flag = 1;
23     cout << (flag ? "YES" : "NO") << endl;
24     if(flag) for(int i = 0; i < n; i++) cout << bus[i] << endl;
25     return 0;
26 }
原文地址:https://www.cnblogs.com/Ash-ly/p/5820472.html