首页 > 代码库 > Codeforces A. Valera and X 题解
Codeforces A. Valera and X 题解
判断二维字符串是否满足下面条件:
- 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"; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。