Codeforces Round #237 (Div. 2) A
链接:http://codeforces.com/contest/404/problem/A
1 second
256 megabytes
standard input
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.
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.
5
xooox
oxoxo
soxoo
oxoxo
xooox
NO
3
wsw
sws
wsw
YES
3
xpx
pxp
xpe
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 ;
}
Codeforces Round #237 (Div. 2) A的更多相关文章
- Codeforces Round #237 (Div. 2) B题模拟题
链接:http://codeforces.com/contest/404/problem/B B. Marathon time limit per test 1 second memory limit ...
- Codeforces Round #237 (Div. 2) B. Marathon(卡long long)
题目:http://codeforces.com/contest/404/problem/B #include <iostream> #include <cstring> #i ...
- Codeforces Round #237 (Div. 2) C. Restore Graph(水构造)
题目大意 一个含有 n 个顶点的无向图,顶点编号为 1~n.给出一个距离数组:d[i] 表示顶点 i 距离图中某个定点的最短距离.这个图有个限制:每个点的度不能超过 k 现在,请构造一个这样的无向图, ...
- Codeforces Round #237 (Div. 2)
链接 A. Valera and X time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inp ...
- [Codeforces Round #237 (Div. 2)] A. Valera and X
A. Valera and X time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
随机推荐
- php版redis插件,SSDB数据库,增强型的Redis管理api实例
php版redis插件,SSDB数据库,增强型的Redis管理api实例 SSDB是一套基于LevelDB存储引擎的非关系型数据库(NOSQL),可用于取代Redis,更适合海量数据的存储.另外,ro ...
- E2PROM的尺寸
买的E2PROM是128*8bit的, 就是只能存储128个byte, 妈的, 买小了. 实际需要的是10句, 可能加两个特殊句, "新手"跟"故障", 一共1 ...
- 在Ubuntu Kylin下安装QQ教程
下载: 下载地址:http://www.ubuntukylin.com/application/show.php?lang=cn&id=279 下载后解压得到wine-qqintl文件夹,里面 ...
- iptables的四表五链
iptables只是Linux防火墙的管理工具而已,位于/sbin/iptables.真正实现防火墙功能的是netfilter,它是Linux内核中实现包过滤的内部结构. iptables包含4个表, ...
- 【JQGRID DOCUMENTATION】.学习笔记.4.Navigator
Navigator是一个将查找或编辑记录的动作,变得非常容易达到用户交互特性.开发者可以创建自定义动作,也可以使用六个预定义的动作.jqGrid为预定义的动作提供icon button图形. 一组完整 ...
- org.hibernate.MappingException: Unknown entity常见问题。回顾笔记,以前没记,现在补上,xiaochao写的蛮好的直接给转载了。
转自http://www.blogjava.net/xiaochao/articles/hibernatetopic.html. 官方说明如下: Hibernate遵循EJB3.0实体bean的注解规 ...
- Ajax案例:简易的购书网页
****使用Ajax可以不需要刷新整个页面,而使局部页面更新的技术: ****JSON是JavaScript得原生格式,JavaScript中处理JSON数据不需要特殊的工具或架包,其规则很简单,对象 ...
- 北邀 E Elegant String
E. Elegant String Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer ...
- 2016年11月16日 星期三 --出埃及记 Exodus 20:7
2016年11月16日 星期三 --出埃及记 Exodus 20:7 "You shall not misuse the name of the LORD your God, for the ...
- qbxt十一系列四
关于考试:题目很难,T1和T3都失误,爆零orz 更正:第三组:不存在相同的字符|str|=26,26<=n<=100 [题目分析] 第一反应,组合数学:第二反应,有端倪:jn给了一道题G ...