2013
12-13

# 九度-1164-旋转矩阵[解题代码]

3
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3

90

java 代码如下：
import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {
static int[][] arr1,arr2;
static int n;
public static void main(String[] args) {
Scanner s = new Scanner(new BufferedInputStream(System.in));
while(s.hasNextInt()){
n = s.nextInt();
arr1 = new int[n][n];
arr2 = new int[n][n];
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
arr1[i][j] = s.nextInt();
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
arr2[i][j] = s.nextInt();
if(f90())
System.out.println(90);
else if(f0())
System.out.println(0);
else if(f180())
System.out.println(180);
else if(f270())
System.out.println(270);
else
System.out.println(-1);

}
}

static boolean f90() {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
if (arr1[i][j] != arr2[j][n - i - 1])
return false;
}
return true;
}
static boolean f0() {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
if(arr1[i][j] != arr2[i][j])
return false;
}
return true;
}
static boolean f180() {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
if (arr1[i][j] != arr2[n-i-1][n-j-1])
return false;
}
return true;
}
static boolean f270() {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
if (arr1[i][j] != arr2[n-j-1][i])
return false;
}
return true;
}

}

/**************************************************************
Problem: 1164
User: coder
Language: Java
Result: Accepted
Time:170 ms
Memory:16840 kb
****************************************************************/