水题,可是还是错了好几次,没有看清.
#include <iostream>
#include <memory.h>
#include <cstdio>
using namespace std;
const int maxn = 12;
int sq[maxn][maxn];
int n ;
bool vis[1200];
int main(){
while(scanf("%d", &n) && n){
memset(sq, 0, sizeof(sq));
memset(vis, 0, sizeof(vis));
int cos = -1, f = 0;
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
scanf("%d", &sq[i][j]);
if(vis[sq[i][j]]){
f = 1;
}
vis[sq[i][j]] = 1;
}
}
for(int i = 0; i < n; ++i){
int s1 = 0 , s2 = 0;
for(int j = 0; j < n; ++j){
s1 += sq[i][j];
s2 += sq[j][i];
}
if(cos == -1){
cos = s1;
}
if(cos != s1 || cos != s2){
f = 1;
break;
}
}
if(f){
printf("No\n");
}else{
int s1 = 0, s2 = 0;
for(int i = 0; i < n; ++i){
s1 += sq[i][i];
s2 += sq[n - i - 1][i];
}
if(s1 != cos || s2 != cos){
printf("No\n");
}else{
printf("Yes\n");
}
}
}
return 0;
}