判断二维字符串是否满足下面条件:
- 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 nsmall
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
唯一一个陷阱:
特殊情况:
3
aaa
aaa
aaa
void ValeraandX() { int n; cin>>n; string s; bool x = true; char dia, nonDia; for (int i = 0; i < n; i++) { cin>>s; for (int k = 0; k < n; k++) { if (0 == i && 0 == k) dia = s[k]; else if (0 == i && 1 == k) nonDia = s[k]; else if (dia == nonDia) { x = false; break; } else if (i == k || k == n-i-1) { if (s[k] != dia) { x = false; break; } } else if (s[k] != nonDia) { x = false; break; } } } if (x) std::cout<<"YES"; else std::cout<<"NO"; }
Codeforces A. Valera and X 题解,布布扣,bubuko.com
时间: 2024-09-30 21:58:25