A. Valera and X

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.

Sample test(s)
input
5
xooox
oxoxo
soxoo
oxoxo
xooox
output
NO
input
3
wsw
sws
wsw
output
YES
input
3
xpx
pxp
xpe
output
NO

题解:模拟。注意所有测试数据都是一个字母的情况。
例如:
3
aaa
aaa
aaa

answer:NO


代码:
 #include<stdio.h>
#include<stdbool.h>
#include<string.h>
#include<limits.h>
int i,j,n,m;
char a[][];
bool can[][]; int
pre()
{
memset(can,true,sizeof(can));
return ;
} int
main()
{
int f;
f=; pre();
scanf("%d",&n);
for(i=;i<=n;i++)
scanf("%s",&a[i]); for(i=;i<=(n >> );i++)
{
if(a[i][i-]!=a[][])
{
f=;
break;
}
if(a[n-i+][i-]!=a[][])
{
f=;
break;
}
if(a[i][n-i]!=a[][])
{
f=;
break;
}
if(a[n-i+][n-i]!=a[][])
{
f=;
break;
}
}
if(a[(n/)+][n/]!=a[][]) f=; if (f==) printf("NO\n");
else
{
f=;
for(i=;i<=(n/);i++)
{
can[i][i-]=false;
can[n-i+][i-]=false;
can[i][n-i]=false;
can[n-i+][n-i]=false;
}
can[(n/)+][n/]=false; for(i=;i<=n;i++)
for(j=;j<n;j++)
if (can[i][j])
{
if(a[i][j]!=a[][])
{
f=;
break;
}
}
if((f==)&&(a[][]!=a[][])) printf("YES\n");
else printf("NO\n"); } return ;
}
 
 

[Codeforces Round #237 (Div. 2)] A. Valera and X的更多相关文章

  1. Codeforces Round #237 (Div. 2) B题模拟题

    链接:http://codeforces.com/contest/404/problem/B B. Marathon time limit per test 1 second memory limit ...

  2. Codeforces Round #237 (Div. 2) A

    链接:http://codeforces.com/contest/404/problem/A A. Valera and X time limit per test 1 second memory l ...

  3. Codeforces Round #252 (Div. 2) B. Valera and Fruits(模拟)

    B. Valera and Fruits time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #237 (Div. 2) B. Marathon(卡long long)

    题目:http://codeforces.com/contest/404/problem/B #include <iostream> #include <cstring> #i ...

  5. Codeforces Round #237 (Div. 2)

    链接 A. Valera and X time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inp ...

  6. Codeforces Round #216 (Div. 2) D. Valera and Fools

    题目链接:http://codeforces.com/contest/369/problem/D 注意题意:所有fools都向编号最小的fool开枪:但每个fool都不会笨到想自己开枪,所以编号最小的 ...

  7. codeforces Round #252 (Div. 2) C - Valera and Tubes

    贪心算法,每条路径最短2格,故前k-1步每次走2格,最后一步全走完 由于数据比较小,可以先打表 #include <iostream> #include <vector> #i ...

  8. Codeforces Round #252 (Div. 2) B. Valera and Fruits

    #include <iostream> #include <vector> #include <algorithm> #include <map> us ...

  9. Codeforces Round #252 (Div. 2) A - Valera and Antique Items

    水题 #include <iostream> #include <set> #include <vector> #include <algorithm> ...

随机推荐

  1. Android4.0强制横屏竖屏

    Android的启动默认是横屏或者竖屏我们的TV本来是横屏显示,但是有客户竟然要竖屏显示,昨天快下班收到的需求,竟然说7.19就要搞定.思路有2个,一个就是修改LCD的默认输出,但是这个不是我这个水平 ...

  2. 获取android源码时repo的错误

    今天用repo获取android源码:../bin/repo init -u git://android.git.kernel.org/platform/manifest.git出现问题:问题一:Tr ...

  3. os8 location authorization 错误.

    今天在XCode6上打开之前写的地图时,给我报这个错 location authorization 去网上查了一番,才知道Xcode6对地图的设置稍有修改 在stackoverflow上找到了答案 i ...

  4. Android窗口管理服务WindowManagerService计算Activity窗口大小的过程分析

    来自http://blog.csdn.net/luoshengyang/article/details/8479101 在Android系统中,Activity窗口的大小是由WindowManager ...

  5. Linq to OBJECT延时标准查询操作符

    1.Where 操作符用于限定输入集合中的元素,将符合条件的元素组织声称一个序列结果.2.Select  操作符用于根据输入序列中的元素创建相应的输出序列中的元素,输出序列中的元素类型可以与输入序列中 ...

  6. 为MVC 添加下载权限

    今天碰到一个错误,极其郁闷,本地开发和本地部署测试没有问题,但是放到阿里云上,出现了权限问题. 报错:ASP.NET 无权访问所请求的资源.请考虑对 ASP.NET 请求标识授予. 参考网上很多资料, ...

  7. NSIS如何对一整个目录文件夹(包括子文件夹和其中的文件)压缩

    原来不加/r参数,NSIS编译器就会不认识文件夹啊. File /r [dir] Reference: http://stackoverflow.com/questions/7973242/nsis- ...

  8. Android驱动之 Linux Input子系统之TP——A/B(Slot)协议

    将A/B协议这部分单独拿出来说一方面是因为这部分内容是比较容易忽视的,周围大多数用到input子系统的开发人员也不甚理解:另一方面是由于这部分知识一旦扩展到TP(触摸屏Touch Panel)的多点触 ...

  9. python中os模块常用方法

    #!/usr/bin/python## os module test import os print 'os.name: ', os.nameprint 'os.getcwd(): ', os.get ...

  10. alert 在手机浏览器会显示网址,怎么能去掉这个网址

    之前就看到有人发过这帖子,现在自己也遇到这问题了. 目前想到的一个解决方案,是用jquery的模拟的alert插件进行代替,可是找的几个插件都不能实现alert的阻塞功能.怎么破 ,具体解决方案如下: ...