我刚才写了一篇,然后点击保存后就消失了。。。 吐槽一下
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.
Input
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.
Output
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
Input
3 xxo xox oxx
Output
YES
Input
4 xxxo xoxo oxox xxxx
Output
NO题意:给一个 n*n 的矩阵,每个点由 x 或者 o 构成。 如果每个点它周围的点中o 的个数为偶数,就是true。
思路:题意理解了,就是扫描一遍。
注意:关键是理解题,昨天别人读的题把我坑惨了。也怪自己英语不好!!六级没过呀!!!明天都要记单词!!!
#include<iostream>
#include<cstdio>
using namespace std;
int main ()
{
char a[102][102];
int tx[4]={-1,0,1,0};
int ty[4]={0,-1,0,1};
int n,i,j,k,qs,bj;
int x,y;
while(cin>>n)
{
bj=0;
qs=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
for(k=0;k<4;k++)
{
x=i+tx[k];
y=j+ty[k];
if(x<0||y<0||x>=n||y>=n)
continue;
else if(a[x][y]=='o')
qs++;
else
;
}
if(qs%2==1)
{
bj=1;
}
}
if(bj==1)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
return 0;
}