这是一道暴力模拟题,上题:
他既然给出了7种情况,那我们就可以开始模拟了;
将旋转转化为坐标之间的变换,这题就好做多了;比如:
旋转90°:arr1[i][j] == arr2[j][n-i-1]
旋转180°:arr1[i][j] != arr2[n-i-1][n-j-1]
...
顺便复习了一下java的静态方法(static)
以下是AC代码:
package P1205;
import java.util.*;
public class Main {
//以下函数返回值为true表示可以通过该方法得到,返回值为false表示不可以通过该方法得到
//转90°
static boolean measure_1(char arr1[][], char arr2[][], int n) {
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;
}
//转180°
static boolean measure_2(char arr1[][], char arr2[][], int n) {
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;
}
//转270°
static boolean measure_3(char arr1[][], char arr2[][], int n) {
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;
}
//反射
static boolean measure_4(char arr1[][], char arr2[][], int n) {
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(arr1[i][j] != arr2[i][n-j-1])return false;
return true;
}
//组合
static boolean measure_5(char arr1[][], char arr2[][], int n) {
//将arr1旋转90°
char temp;
for(int i = 0;i<n;i++)
for(int j=0;j<=(n/2-1);j++) {
temp = arr1[i][j];
arr1[i][j] = arr1[i][n-j-1];
arr1[i][n-j-1] = temp;
}
if(measure_1(arr1,arr2,n) || measure_2(arr1,arr2,n) || measure_3(arr1,arr2,n))return true;
return false;
}
//不改变
static boolean measure_6(char arr1[][], char arr2[][], int n) {
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;
}
public static void main(String[] args) {
//录入数据
Scanner in = new Scanner(System.in);
int n = in.nextInt();
char arr1[][] = new char[n][n];
char arr2[][] = new char[n][n];
for(int i=0;i<n;i++) {
String s1 = in.next();
for(int j=0;j<n;j++) {
arr1[i][j] = s1.charAt(j);
}
}
for(int i=0;i<n;i++) {
String s1 = in.next();
for(int j=0;j<n;j++) {
arr2[i][j] = s1.charAt(j);
}
}
//处理数据
if(measure_1(arr1,arr2,n))System.out.print("1");
else if(measure_2(arr1,arr2,n))System.out.print("2");
else if(measure_3(arr1,arr2,n))System.out.print("3");
else if(measure_4(arr1,arr2,n))System.out.print("4");
else if(measure_5(arr1,arr2,n))System.out.print("5");
else if(measure_6(arr1,arr2,n))System.out.print("6");
else System.out.print("7");
}
}