天天看點

問題 1752: 對稱矩陣

題目連結:​​https://www.dotcpp.com/oj/problem1752.html​​

題目描述

輸入一個N維矩陣,判斷是否對稱。

輸入

輸入第一行包括一個數:N(1<=N<=100),表示矩陣的維數。

接下來的N行,每行包括N個數,表示N*N矩陣的元素。

輸出

可能有多組測試資料,對于每組資料,

輸出"Yes!”表示矩陣為對稱矩陣。

輸出"No!”表示矩陣不是對稱矩陣。

樣例輸入

1
68 
3
1 70 25 
70 79 59 
25 59 63 
3
6 46 82 
28 62 92 
96 43 28      

樣例輸出

Yes!
Yes!
No!      
1 #include <iostream>
 2 #include <algorithm>
 3 #include <cmath> 
 4 #include <string>
 5 #include <cstring>
 6 #include <map> 
 7 #include <cstdio>
 8 using namespace std;
 9 int a[105][105]; 
10 int n,tmp; 
11 int main()
12 {
13     while(cin>>n){
14         for(int i=0;i<n;i++){
15             for(int j=0;j<n;j++){
16                 cin>>a[i][j];
17             }
18         }
19         int flag=1;
20         for(int i=0;i<n;i++){
21             for(int j=0;j<i;j++){
22                 if(a[i][j]!=a[j][i]){
23                     flag=0;
24                     break;
25                 }
26             }
27         }
28         if(flag) cout<<"Yes!"<<endl;
29         else cout<<"No!"<<endl;
30     }
31     return 0;
32 }