【Codeforces Round #369 (Div. 2)】Codeforces 711A Bus to Udayland

来源:互联网 发布:python进入命令行模式 编辑:程序博客网 时间:2024/05/21 09:16

ZS the Coder and Chris the Baboon are travelling to Udayland! To get
there, they have to get on the special IOI bus. The IOI bus has n rows
of seats. There are 4 seats in each row, and the seats are separated
into pairs by a walkway. When ZS and Chris came, some places in the
bus was already occupied.

ZS and Chris are good friends. They insist to get a pair of
neighbouring empty seats. Two seats are considered neighbouring if
they are in the same row and in the same pair. Given the configuration
of the bus, can you help ZS and Chris determine where they should sit?
Input

The first line of the input contains a single integer n (1 ≤ n ≤ 1000)
— the number of rows of seats in the bus.

Then, n lines follow. Each line contains exactly 5 characters, the
first two of them denote the first pair of seats in the row, the third
character denotes the walkway (it always equals ‘|’) and the last two
of them denote the second pair of seats in the row.

Each character, except the walkway, equals to ‘O’ or to ‘X’. ‘O’
denotes an empty seat, ‘X’ denotes an occupied seat. See the sample
cases for more details. Output

If it is possible for Chris and ZS to sit at neighbouring empty seats,
print “YES” (without quotes) in the first line. In the next n lines
print the bus configuration, where the characters in the pair of seats
for Chris and ZS is changed with characters ‘+’. Thus the
configuration should differ from the input one by exactly two
charaters (they should be equal to ‘O’ in the input and to ‘+’ in the
output).

If there is no pair of seats for Chris and ZS, print “NO” (without
quotes) in a single line.

If there are multiple solutions, you may print any of them.

模拟。

#include<cstdio>#include<cstring>char s[1010][10];int main(){    int i,j,k,m,n,p,q,x,y,z;    bool flag;    scanf("%d",&n);    for (i=1;i<=n;i++)      scanf("%s",s[i]+1);    flag=0;    for (i=1;i<=n;i++)    {        if (s[i][1]=='O'&&s[i][2]=='O')        {            s[i][1]=s[i][2]='+';            flag=1;            break;        }        if (s[i][4]=='O'&&s[i][5]=='O')        {            s[i][4]=s[i][5]='+';            flag=1;            break;        }    }    if (!flag) printf("NO\n");    else    {        printf("YES\n");        for (i=1;i<=n;i++)          printf("%s\n",s[i]+1);    }}
0 0
原创粉丝点击