Codeforces Round #237 (Div. 2) A

链接:http://codeforces.com/contest/404/problem/A

A. Valera and X
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals n squares (n is an odd number) and each unit square contains some small letter of the English alphabet.

Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:

  • on both diagonals of the square paper all letters are the same;
  • all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.

Help Valera, write the program that completes the described task for him.

Input

The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.

Output

Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.

Sample test(s)
input
5
xooox
oxoxo
soxoo
oxoxo
xooox
output
NO
input
3
wsw
sws
wsw
output
YES
input
3
xpx
pxp
xpe
output
NO

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
这题作为CF 的A题确实很好,题意很简单,代码很简单,就是有坑,遍地是坑……
也可以说自己没有身经百战,总是掉坑里。。。。
 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm> using namespace std; int main()
{
char str[][];
int i,j,n;
while(scanf("%d",&n)!=EOF)
{
getchar();
for(i=; i<=n; i++)
{
for(j=; j<=n; j++)
{
scanf("%c",&str[i][j]);
}
getchar();
}
int tmp=n;
char xx=str[][];
char yy=str[][];
bool flag=true;
if(xx == yy)
{
printf("NO\n");
continue;
}
for(i=; i<=n; i++)
{
if(str[i][i] != xx)
{
//printf("NO\n");
flag=false;
break;
}
if(str[i][tmp] != xx)
{
//printf("NO\n")
flag=false;
break;
}
tmp--;
}
for(i=; i<=n; i++)
{
for(j=; j<=n; j++)
{
if(str[i][j] != xx && str[i][j] != yy)
{
flag = false;
goto end;
}
}
}
tmp=n;
for(i=; i<=n; i++)
{
for(j=; j<=n; j++)
{
if(i == j || j == tmp)
continue;
if(str[i][j] == xx)
{
flag=false;
//goto end;
}
}
tmp--;
}
end:;
if(flag)printf("YES\n");
else printf("NO\n");
}
return ;
}
上一篇:GlusterFS 配置及使用


下一篇:poj1721