首页 > 其他 > 详细

Codeforces A. Valera and X 题解

时间:2014-05-23 02:20:41      阅读:439      评论:0      收藏:0      [点我收藏+]

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

  • 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 题解

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!