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连试试水的深浅..... ...
随机推荐
- android 学习随笔二(读写文件)
在android读写文件 RAM:运行内存,相当于电脑的内存 ROM:内部存储空间,相当电脑硬盘,android手机必须有的 SD卡:外部存储空间,相当电脑的移动硬盘,不是必须的.手机如果内置16G存 ...
- CentOS修改主机名和网络信息
1.修改主机名称 [root@centos ~]# vim /etc/sysconfig/network打开文件,修改以下内容并保存 NETWORKING=yes #使用网络 HOSTNAME=cen ...
- Xcode 项目配置学习
Xcode有四种build for 分别是: build for Running build for Testing build for Profiling build for Archiving R ...
- Linux设备驱动之semaphore机制【转】
转自:http://blog.csdn.net/xiao229404041/article/details/7031776 Linux设备驱动之semaphore机制在Linux系统中,信号号是一种重 ...
- 图解 交集(join)和 合并(union)
假设我们有两张表. Table A 是左边的表. Table B 是右边的表. 其各有四条记录,其中有两条记录是相同的,如下所示: id name id name 1 Pirate ...
- JVM 指令集
指令码 助记符 说明 0x00 nop 什么都不做 0x01 aconst_null 将null推送至栈顶 0x02 iconst_m1 将int型-1推送至栈顶 0x03 iconst_0 将int ...
- web.xml完整配置
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java ...
- 分布式拒绝服务攻击(DDoS)原理及防范
DDoS攻击概念 DoS的攻击方式有很多种,最基本的DoS攻击就是利用合理的服务请求来占用过多的服务资源,从而使合法用户无法得到服务的响应. DDoS攻击手段是在传统的DoS攻击基础之上产生的一类攻击 ...
- 完整学习git三 查看暂存区目录树 git diff
1显示暂存区中的目录树 git ls-files git ls-tree git diff 魔法 1工作区与暂存区比较 git diff 2工作区与HEAD比较 git diff HEAD 3暂存区与 ...
- 八大排序算法之六--交换排序—快速排序(Quick Sort)
基本思想: 1)选择一个基准元素,通常选择第一个元素或者最后一个元素, 2)通过一趟排序讲待排序的记录分割成独立的两部分,其中一部分记录的元素值均比基准元素值小.另一部分记录的 元素值比基准值大. 3 ...