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 学习随笔三(测试与单元测试框架)
测试 1.按岗位: 黑盒测试:测试业务逻辑 白盒测试:测试逻辑方法 2.按测试粒度 方法测试 function 单元测试 unit 集成测试 integration 系统测试 system 3.按暴力 ...
- 【python cookbook】【数据结构与算法】12.找出序列中出现次数最多的元素
问题:找出一个元素序列中出现次数最多的元素是什么 解决方案:collections模块中的Counter类正是为此类问题所设计的.它的一个非常方便的most_common()方法直接告诉你答案. # ...
- 161025、java提高篇之关键字static
一. static代表着什么 在Java中并不存在全局变量的概念,但是我们可以通过static来实现一个"伪全局"的概念,在Java中static表示"全局"或 ...
- 将UTF8编码的3字节中英文转成2字节中英文.
1. 首先要考虑将String转成一个bytes的数组, 每个汉字是3个bytes, 英文或者标点是1个byte. 2. 然后去判断一下每一个byte的前面几个bit, 看下面的表, 1个byte的字 ...
- ctl 里面pdef解说
WRF 模式MM5 模式都是目前从网上可以下载的气象软件,因此在国内经常可以见到.但这两种模式的数据特点数据的水平网格都不是标准的经纬度网格.需要在ctl 文件中加入PDEF 定义说明把这种非标准的数 ...
- ios tabbar 文字位置
[nav.tabBarItem setTitlePositionAdjustment)];
- Asp.net mvc5 解析route源码实现自己的route系统
url route 路由系统的责任是找到匹配的路由,创建路由数据,并将请求分配给一个处理程序. 选择动作是 MVC 的处理程序的实现细节.它使用路由数据和从传入请求其他信息来选择要执行的操作 实例 源 ...
- 上传图片到阿里云OSS和获取上传图片的外网url的步骤
啥都不说 直接上代码 1.html: <form action="/bcis/api/headImgUpload.json" method="post" ...
- ACM题目————Anagram
Description You are to write a program that has to generate all possible words from a given set of l ...
- 关于匿名类无法转换为object
缘由,不能在Razor中使用匿名类, 先事先封装了一个方法,用于Razor给cshtml模板返回页面. 在ashx一般处理程序中,是这样调用的 匿名类的格式如下:(只看格式,不看具体内容) 调用这样 ...