UVA11349




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.





大意:給一個矩陣 問你是否是對稱性矩陣(即是Mij = Mji)

解法:以中心點為對稱比較 (檢驗一半即可) or 一維陣列檢驗(將數字以列拉直後會發現成迴文)





import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class UVA11349 {

 public static void main(String[] args) throws NumberFormatException,
   IOException {

  BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

  int count = Integer.parseInt(bf.readLine());

  int k = 1;

  StringBuilder sb = new StringBuilder();

  for (int c = 0; c < count; c++) {

   String s[] = bf.readLine().split(" ");

   int N = Integer.parseInt(s[2]);

   boolean check = true;

   long N_matrix[][] = new long[N][N];

   for (int i = 0; i < N; i++) {

    String temp[] = bf.readLine().split(" ");

    for (int j = 0; j < N; j++) {

     N_matrix[i][j] = Long.parseLong(temp[j]);

     if (N_matrix[i][j] < 0) {
      check = false;
      break;
     }

    }

   }

   if (check == false) {

    sb.append("Test #" + k + ": Non-symmetric." + "\n");
    k++;
    continue;
   }

   int center = 0;

   if (check)
    center = (N + 1) / 2;

   for (int i = 0; i < center; i++) {

    for (int j = 0; j < N; j++) {

     if (N_matrix[i][j] != N_matrix[(N - i - 1)][(N - j - 1)]) {
      check = false;
      break;
     }

    }

   }

   sb.append("Test #" + k + ": "
     + (check == true ? "Symmetric." : "Non-symmetric.") + "\n");

   k++;
  }

  System.out.print(sb);

 }

}