标签:des style blog class c code
判断二维字符串是否满足下面条件:
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 nsmall 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
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
标签:des style blog class c code
原文地址:http://blog.csdn.net/kenden23/article/details/26578863