【CODEFORCES】 A. Appleman and Easy Task

来源:互联网 发布:肯尼迪绕丝数据 编辑:程序博客网 时间:2024/06/05 18:48

A. Appleman and Easy Task
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.

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.

Sample test(s)
input
3xxoxoxoxx
output
YES
input
4xxxoxoxooxoxxxxx
output
NO


枚举每个点,然后输出....

#include<iostream>#include<cstdio>#include<cstring>using namespace std;char s[105][105]; int a[105][105],i,j,n;int _check(){    for (int i=0;i<n;i++)        for (int j=0;j<n;j++)        if (a[i][j]%2!=0)  return 0;    return 1;}int main(){    memset(s,0,sizeof(s));    scanf("%d",&n);    for (i=0;i<n;i++) scanf("%s",&s[i]);    for (i=0;i<n;i++)        for (j=0;j<n;j++)        {            if (s[i-1][j]=='o' && i-1>=0) a[i][j]++;            if (s[i+1][j]=='o') a[i][j]++;            if (s[i][j-1]=='o' && j-1>=0) a[i][j]++;            if (s[i][j+1]=='o') a[i][j]++;        }    if (_check()) cout <<"YES";    else cout <<"NO";    return 0;}







0 0
原创粉丝点击