Valera and X
来源:互联网 发布:淘宝设计师学徒招聘 编辑:程序博客网 时间:2024/06/05 16:07
Description
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 equalsn 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 containsn 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 Input
5xoooxoxoxosoxoooxoxoxooox
NO
3wswswswsw
YES
3xpxpxpxpe
NO#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int n;char str[500][500];bool flag=true;int main(){ cin>>n; for(int i=0;i<n;i++){ scanf("%s",str[i]); } char sg=str[0][0]; for(int i=0;i<n;i++){ if(str[i][i]!=sg||str[i][n-1-i]!=sg){ flag=false; break; } } if(!flag||sg==str[0][1]){ puts("NO"); return 0; } sg=str[0][1]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(i==j||j==n-1-i) continue; if(str[i][j]!=sg){ flag=false; break; } } } if(flag){ puts("YES"); } else{ puts("NO"); } return 0;}
- Valera and X
- A. Valera and X
- A. Valera and X
- A. Valera and X
- Valera and X
- Valera and X
- code forces 404A Valera and X
- codeforces 404A - Valera and X
- Codeforces A. Valera and X 题解
- cf-404A Valera and X
- CodeForces - 404A: Valera and X
- CodeForces 404A Valera and X【水题】
- Codeforces Round #237 (Div. 2) A. Valera and X
- codeforce Valera and Plates
- codeforce Valera and Contest
- B. Valera and Contest
- A. Valera and Plates
- Valera and Fruits
- 无法使用虚拟目录密码作为用户在本地登录到网站
- postgresql数据库的摸索
- 【郑轻】[1820]LT的求助
- uva704
- LeetCode[263] Ugly Number(Java)
- Valera and X
- 最小机器重量设计问题(回溯法-满m叉树)
- hdu 计算机学院大学生程序设计竞赛(2015’12)The Country List
- AS上butterknife插件安装与使用
- struts2学习
- uva10905
- 【郑轻】[1821]YZ的解密游戏
- hdu 计算机学院大学生程序设计竞赛(2015’12)Happy Value(最大生成树)
- 图---互斥集