Created
April 14, 2011 05:56
-
-
Save stphung/918967 to your computer and use it in GitHub Desktop.
My solution to "Transformations" from USACO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
ID: stphung1 | |
LANG: JAVA | |
TASK: transform | |
*/ | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
import java.util.Arrays; | |
import java.util.Scanner; | |
class transform { | |
public static void main(String[] args) throws IOException { | |
Scanner sc = new Scanner(new File("transform.in")); | |
PrintWriter pw = new PrintWriter(new File("transform.out")); | |
int n = sc.nextInt(); | |
char[][] input = new char[n][n]; | |
for(int i=0; i<input.length; i++) { | |
String s = sc.next(); | |
for(int j=0; j<input[i].length; j++) { | |
input[i][j] = s.charAt(j); | |
} | |
} | |
char[][] target = new char[n][n]; | |
for(int i=0; i<target.length; i++) { | |
String s = sc.next(); | |
for(int j=0; j<target[i].length; j++) { | |
target[i][j] = s.charAt(j); | |
} | |
} | |
if (Arrays.deepEquals(cw(input), target)) { | |
pw.println(1); | |
} else if (Arrays.deepEquals(cw(cw(input)), target)) { | |
pw.println(2); | |
} else if (Arrays.deepEquals(cw(cw(cw(input))), target)) { | |
pw.println(3); | |
} else if (Arrays.deepEquals(reflect(input), target)) { | |
pw.println(4); | |
} else if ((Arrays.deepEquals(cw(reflect(input)), target)) || | |
(Arrays.deepEquals(cw(cw(reflect(input))), target)) || | |
(Arrays.deepEquals(cw(cw(cw(reflect(input)))), target))) { | |
pw.println(5); | |
} else if (Arrays.deepEquals(input, target)) { | |
pw.println(6); | |
} else { | |
pw.println(7); | |
} | |
pw.close(); | |
} | |
private static void print(char[][] input) { | |
for(int i=0; i<input.length; i++) { | |
for(int j=0; j<input.length; j++) { | |
System.out.print(input[i][j]); | |
} | |
System.out.println(); | |
} | |
} | |
private static char[][] cw(char[][] input) { | |
char[][] ret = new char[input.length][input.length]; | |
for(int i=0; i<input.length; i++) { | |
for(int j=0; j<input.length; j++) { | |
ret[j][input.length-i-1] = input[i][j]; | |
} | |
} | |
return ret; | |
} | |
private static char[][] reflect(char[][] input) { | |
char[][] ret = new char[input.length][input.length]; | |
for(int i=0; i<input.length; i++) { | |
for(int j=0; j<input.length; j++) { | |
ret[i][j] = input[i][input.length-j-1]; | |
} | |
} | |
return ret; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment