对称矩阵的判定
来源:互联网 发布:小米电力猫网络密码 编辑:程序博客网 时间:2024/06/05 21:00
Problem Description
输入矩阵的行数,再依次输入矩阵的每行元素,判断该矩阵是否为对称矩阵,若矩阵对称输出“yes”,不对称输出”no“。
Input
输入有多组,每一组第一行输入一个正整数N(N<=20),表示矩阵的行数(若N=0,表示输入结束)。
下面依次输入N行数据。
Output
若矩阵对称输出“yes”,不对称输出”no”。
Example Input
3
6 3 12
3 18 8
12 8 7
3
6 9 12
3 5 8
12 6 3
0
Example Output
yes
no
#include <iostream>#include <stdio.h>using namespace std;int a[80][80];int main(){ int n; int flag; while(cin>>n&& n!=0) { flag = 1; for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { cin>>a[i][j]; } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { if(a[i][j] != a[j][i]) { flag = 0; break; } } } if(flag == 0) cout<<"no"<<endl; else cout<<"yes"<<endl; } return 0;}
阅读全文