【JAVA】UVA 11349 Symmetric Matrix

題目原文:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2324

Sample Input
2
N = 3
5 1 3
2 0 2
3 1 5

N = 3
5 1 3
2 0 2
0 1 5

Sample Output

Test #1: Symmetric.
Test #2: Non-symmetric.

題目大意:判斷是否為對稱矩陣,(1,1)=(3,3),(1,2)=(3,2),(1,3)=(3,1),(2,1)=(2,3)

注意:若矩陣A與其置換矩陣A^T相等,則A稱為對稱矩陣,且對稱矩陣必為方陣。
(A^T)ij=(A)ji

import java.util.*;
public class main{
    public static void main(String[] args) {
            Scanner sc=new Scanner(System.in);
           	int n = sc.nextInt(); //有幾個對稱矩陣需要判斷
           	
           	for(int i=0;i<n;i++){
           		String t1=sc.next(),t2=sc.next(); //t1為N , t2為=
           		
           		int k = sc.nextInt(); //幾乘幾的對稱矩陣
           		long arr[] = new long [k*k];
           		int size = k*k;
           		
           		for(int j=0;j<size;j++){
           			arr[j] = sc.nextInt(); //輸入矩陣所有的值
           		}
           		
           		boolean flag=true;
           		
           		for(int j=0;j<size;j++){
           			if(arr[j]<0 || arr[j]!=arr[size-1-j]){ //判斷是否為對稱
           				flag=false;
           				break;
           			}
           		}
           		if(flag){
           			System.out.println("Test #"+(i+1)+": Symmetric.");
           		}else{
           			System.out.println("Test #"+(i+1)+": Non-symmetric.");
           		}
           		
           	}
    }
};