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. Android 之 Window、WindowManager 与窗口管理

    其实在android中真正展示给用户的是window和view,activity在android中所其的作用主要是处理一些逻辑问题,比如生命周期的管理.建立窗口等.在android中,窗口的管理还是比 ...

  2. XJOI网上同步训练DAY6 T2

    思路:记得FJ省队集训好像有过这题,可是我太弱了,根本不懂T_T #include<cstdio> #include<iostream> #include<cmath&g ...

  3. 用keil怎么像makefile那样选择哪些文件进行编译?

    因为设备有多种不同的型号的硬件,所以就有不同的驱动,我想在编译的时候,像在linux下的makeile那样,自己写一个编译连接的东西,来控制我哪些文件进行编译链接,不知道在keil下有没有这样的方法. ...

  4. [置顶] 【cocos2d-x入门实战】微信飞机大战之十三:游戏场景过渡

    原创作品,转载请标明:http://blog.csdn.net/jackystudio/article/details/12082043 游戏是实现了,但是如果有个欢迎界面和一个结束界面就更好了. 欢 ...

  5. JDBC中Statement接口提供的execute、executeQuery和executeUpdate之间的区别

    Statement 接口提供了三种执行 SQL 语句的方法:executeQuery.executeUpdate 和 execute.使用哪一个方法由 SQL 语句所产生的内容决定. 方法execut ...

  6. 左侧高亮(js)

    //左导航高亮 (function(){ var leftnav = $('#leftnav');  //左侧ul var pi = __preset.curpathid; if(pi=='/acco ...

  7. 使用面向 iOS 的本机插件扩展

    本文细致探讨了 Xcode(以 iOS 设备为目标)中的 PhoneGap(也称为 Apache Cordova)应用程序本机插件.如果您刚开始接触 PhoneGap 或者需要回顾 PhoneGap ...

  8. 斐波那契数列 Php练手

    数列从第三项开始,每一项都等于前两项之和. F0=0,F1=1,Fn=F(n-1)+F(n-2) 递归版和非递归版. <?php function fib($n){ $array = array ...

  9. JSP简单练习-数组应用实例

    <%@ page contentType="text/html; charset=gb2312" %> <html> <body> <% ...

  10. AVR32开发环境搭建

    下面是搭建AVR32开发环境的过程记录: 1.AVR32的编译环境下载  (到这里下载  as5installer-stable-5.1.208-full.exe) 如果你在安装的过程中碰到如下问题: ...