1 second
256 megabytes
standard input
standard output
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
3
xxo
xox
oxx
YES
4
xxxo
xoxo
oxox
xxxx
NO
英语真的是差啊,没办法,没理解,好好学英语,这学期过CET4,加油!
遍历搞一下这道题就过了。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std;
const int max_size = ; int d1[] = {-, , , };
int d2[] = {, -, , }; bool check(int x, int y, int n)
{
if(x >= && y >= && x < n && y < n)
return true;
return false;
} int main()
{
int n;
int graph[max_size][max_size]; while(scanf("%d%*c", &n) != EOF)
{
for(int i = ; i < n; i++)
{
for(int j = ; j < n; j++)
{
char a = getchar();
if(a == 'o')
graph[i][j] = ;
else
graph[i][j] = ;
}
getchar();
} int tag = false;
for(int i = ; i < n; i++)
{
for(int j = ; j < n; j++)
{
int ans = ;
int x, y;
for(int k = ; k < ; k ++)
{
x = i + d1[k];
y = j + d2[k];
if(check(x, y, n))
{
if(graph[x][y] == )
ans++;
}
}
if(ans % != )
{
printf("NO\n");
tag = true;
break;
}
}
if(tag == true)
break;
}
if(tag == false)
printf("YES\n");
}
return ;
}