码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces A. Valera and X 题解

时间:2014-05-23 02:21:01      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   class   c   code   

判断二维字符串是否满足下面条件:

  • 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?<?300n is odd). Each of the next n lines contains nsmall 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

唯一一个陷阱:

特殊情况:
3
aaa
aaa
aaa

void ValeraandX()
{
	int n;
	cin>>n;
	string s;
	bool x = true;
	char dia, nonDia;
	for (int i = 0; i < n; i++)
	{
		cin>>s;
		for (int k = 0; k < n; k++)
		{
			if (0 == i && 0 == k) dia = s[k];
			else if (0 == i && 1 == k) nonDia = s[k];
			else if (dia == nonDia)
			{
				x = false;
				break;
			}
			else if (i == k || k == n-i-1)
			{
				if (s[k] != dia)
				{
					x = false;
					break;
				}
			}
			else if (s[k] != nonDia)
			{
				x = false;
				break;
			}
		}
	}
	if (x) std::cout<<"YES";
	else std::cout<<"NO";
}



Codeforces A. Valera and X 题解,布布扣,bubuko.com

Codeforces A. Valera and X 题解

标签:des   style   blog   class   c   code   

原文地址:http://blog.csdn.net/kenden23/article/details/26578863

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!