CodeForces - 404A: Valera and X
来源:互联网 发布:岳云鹏 于谦 知乎 编辑:程序博客网 时间:2024/06/06 18:07
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.
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.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
5xoooxoxoxosoxoooxoxoxooox
NO
3wswswswsw
YES
3xpxpxpxpe
NO
# include <stdio.h># include <string.h>int main(){ int n, i, j ,flag = 0; char s[302][302], c, d; scanf("%d",&n); for(i=1; i<=n; ++i) scanf("%s",s[i]+1); c = s[1][1];//保存第一个字符 d = s[1][2];//保存第二个字符 if(c == d) { puts("NO"); return 0; } for(i=1; i<=n/2; ++i)//先遍历到中间行 { if(s[i][i] != s[i][n-i+1] || s[i][i] != c || s[i][i]==d) flag = 1; for(j=1; j<=n; ++j) { if(j==i || j==n-i+1) continue; else if(s[i][j] != d) { flag = 1; break; } } if(flag) break; } for(i=n/2+1; i<=n; ++i)//再遍历后面的行 { if(s[i][n-i+1] != s[i][i] || s[i][i] != c || s[i][i]==d) flag = 1; for(j=1; j<=n; ++j) { if(j==n-i+1 || j==i) continue; else if(s[i][j] != d) { flag = 1; break; } } if(flag) break; } if(flag) puts("NO"); else puts("YES"); return 0;}
- codeforces 404A - Valera and X
- CodeForces - 404A: Valera and X
- CodeForces 404A Valera and X【水题】
- Codeforces A. Valera and X 题解
- A. Valera and X
- A. Valera and X
- A. Valera and X
- code forces 404A Valera and X
- cf-404A Valera and X
- Codeforces Round #237 (Div. 2) A. Valera and X
- codeforces A. Valera and Plates 题解
- CodeForces 441 A. Valera and Antique Items
- CodeForces 252A-Valera and Antique Items
- CodeForces 441A Valera and Antique Items
- CodeForces 379A Valera and Plates
- CodeForces 441A Valera and Antique Items
- codeforces 441A Valera and Antique Items
- Codeforces Round #237 (Div. 2) A. Valera and X(模拟题)
- java调用python脚本
- linux python 更新版本
- ipython文档路径配置
- 《MySQL必知必会》学习笔记
- echart,折线图,两条线之间的阴影
- CodeForces - 404A: Valera and X
- Lucene 6.0 提取新闻关键词Top-N
- PHAssetResourceRequestOptions progressHandler/PHAssetResourceProgressHandler
- HDU-1059 Dividing (多重背包)
- 决策树算法
- 安卓中为了获取context的方法和区别
- 20161230C++阶段班03_Object C++_03构造函数/命名空间/初始化列
- Spring MVC---基于注解的控制器
- mac提示Operation not permitted的解决方法和安装MAMP集成环境后使用mysql命令的问题