【題解】CPE 一顆星選集:21. Symmetric Matrix

題目

Symmetric: all elements are non-negative, symmetric to the center
m[i][j] (-2^32 ~ 2^32), n (1~100)
UVa 連結
ZeroJudge 連結

解法

本題很簡單。

#include <iostream>
#define ll long long
using namespace std;

int main(){
    int T, n;
    char c;
    cin >> T;
    for(int t=1; t<=T; t++){
        cin >> c >> c >> n;
        ll m[n][n];
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                cin >> m[i][j];
            }
        }
        bool symmetric = true;
       for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if(m[i][j] != m[n-1-i][n-1-j] || m[i][j] < 0 || m[n-1-i][n-1-j] < 0){
                    symmetric = false;
                    break;
                }
            }
        }
        cout << "Test #" << t << ": ";
        if(symmetric) cout << "Symmetric.\n";
        else cout << "Non-symmetric.\n";
    }
}
👉 回到:【CPE大學程式能力檢定】目錄
發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *