地址:http://codeforces.com/contest/404/problem/A
题意:判断矩阵是否为"X",水题,暴力即可····
难点是如何判断对角线和非对角线,这个一会在代码中标出···
代码如下:
#include <iostream> #include<string.h> using namespace std; int main() { int i,j,n; int flag=1; char a[999][999]; cin>>n; for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ cin>>a[i][j]; } } char c,d; c=a[1][1];d=a[1][2]; for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ if(i==j){//对角线 if(a[i][j]!=c){flag=0;break;} } else if(i+j==n+1){if(a[i][j]!=c){flag=0;break;}}//对角线 else{ if((a[i][j]==c)||a[i][j]!=d){flag=0;break;}//非对角线元素 } } } if(flag) cout<<"YES"<<endl; else cout<<"NO"<<endl; //cout << "Hello world!" << endl; return 0; }