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连试试水的深浅..... ...
随机推荐
- javaWeb 使用jsp开发 if 标签
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...
- android 之 Crash信息的持久化处理
需求: 持久化运行时异常的信息 1.CrashHandler.java import android.content.Context; import android.content.pm.Packag ...
- Mysql备份与还原实例
一.备份数据库 ----清空一下日志 mysql> reset master; Query OK, rows affected (0.02 sec) ----查看一下echo表的存储引擎 mys ...
- 十步完全理解 SQL(转载)
英文出处:Lukas Eder. 很多程序员视 SQL 为洪水猛兽.SQL 是一种为数不多的声明性语言,它的运行方式完全不同于我们所熟知的命令行语言.面向对象的程序语言.甚至是函数语言(尽管有些人认为 ...
- 《深度探索C++对象模型》3
第六章:执行期语意学 全局对象的初始化: 局部静态对象的初始化: 构建对象数组的vec_new()函数: 针对数组的new操作: placement operator new: 反聚合提高效率: 模板 ...
- hdwiki中model模块的应用
control中调用model原则是这样的,如果你的这个model在本control中大部分方法中都要用到,那么,就写在构造函数里面.例如,名字为doc的control的构造函数如下: functio ...
- python正则表达式之元字符介绍
python中元字符及其含义如下: 元字符 含义 . 匹配除换行符以外的任意一个字符 ^ 匹配行首 $ 匹配行尾 ? 重复匹配0次或1次 * 重复匹配0次或更多次 + 重复匹配1次或更多次 {n,} ...
- python: linux下安装redis
Python连接时报拒绝连接,需要重装redis: 1) 卸载redis sudo apt-get remove redis-server sudo apt-get autoremove 2)编译安装 ...
- Linux hrtimer分析(2)
http://blog.csdn.net/angle_birds/article/details/17375901 本文介绍Linux2.6.29中,配置高精度模式的hrtimer与未配置高精度模式时 ...
- javaWEB小练习:在数据库中查找相同的username和password
/*练习题: * 在Mysql数据库中创建一个person数据表,添加三个字段,id,user,password,并录入几条记录 * *练习题:定义一个login.html,里面定义了两个请求字段:u ...