对称矩阵的判定
Time Limit: 1000 ms
Memory Limit: 65536 KiB
Problem Description
输入矩阵的行数,再依次输入矩阵的每行元素,判断该矩阵是否为对称矩阵,若矩阵对称输出“yes",不对称输出”no“。
Input
输入有多组,每一组第一行输入一个正整数N(N<=20),表示矩阵的行数(若N=0,表示输入结束)。
下面依次输入N行数据。
Output
若矩阵对称输出“yes",不对称输出”no”。
Sample Input
3 6 3 12 3 18 8 12 8 7 3 6 9 12 3 5 8 12 6 3 0
Sample Output
yes no
Hint
Source
注意:flat的定义位置
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int n;
int i,j;
while(~scanf("%d",&n)&&n){
int flag=1;
int a[n][n];
for(i=0;i<n;i++){
for(j=0;j<n;j++){
cin>>a[i][j];
}
}
for(i=1;i<n;i++){
for(j=0;j<i;j++){
if(a[i][j]!=a[j][i]){
flag=0;
break;
}
}
}
if(flag==1){
cout<<"yes"<<endl;
}else{
cout<<"no"<<endl;
}
}
}