1 #include "iostream" 2 #include "cstdio" 3 #include "cstring" 4 #include "algorithm" 5 using namespace std; 6 char mat[310][310]; 7 int n; 8 bool check_1() 9 { 10 int i; 11 char c = mat[1][1]; 12 for(i = 1; i <= n; ++i) { 13 if(c != mat[i][i] || c != mat[i][n + 1 - i]) 14 return 0; 15 } 16 return 1; 17 } 18 19 bool check_2() 20 { 21 int i, j; 22 char c = mat[1][2]; 23 for(i = 1; i <= n; ++i) { 24 for(j = 1; j <= n; ++j) { 25 if(i == j || n + 1 - i == j) 26 continue; 27 if(c != mat[i][j]) 28 return 0; 29 } 30 } 31 return 1; 32 } 33 34 int main() 35 { 36 int i, j; 37 scanf("%d", &n); 38 for(i = 1; i <= n; ++i) 39 scanf("%s", mat[i] + 1); 40 if(mat[1][1] != mat[1][2] && check_1() && check_2()) 41 printf("YES\n"); 42 else 43 printf("NO\n"); 44 }
时间: 2024-10-14 06:38:46