Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class Matrix {
- private static int[][] rotate(String degree, int[][] anArray) {
- int[][] anotherArray;
- int i, j, k, l, n, end;
- n = anArray.length;
- end = n - 1;
- anotherArray = new int[n][n];
- if (degree.equals("90")){
- for (i = 0; i < n; i++){
- for (j = 0; j < n; j++){
- anotherArray[i][j] = anArray[end - j][i];
- }
- }
- } else if (degree.equals("180")){
- for (i = 0; i < n; i++){
- for (j = 0; j < n; j++){
- anotherArray[i][j] = anArray[end - i][end - j];
- }
- }
- } else if (degree.equals("270")){
- for (i = 0; i < n; i++){
- for (j = 0; j < n; j++){
- anotherArray[i][j] = anArray[j][end - i];
- }
- }
- }
- return anotherArray;
- }
- private static int[][] reflectX(int[][] anArray) {
- int i, j, k, l, n, end;
- int[][] anotherArray;
- n = anArray.length;
- anotherArray = new int[n][n];
- end = n - 1;
- for (i = 0; i < n; i++){
- for (j = 0; j <n; j++){
- anotherArray[i][j] = anArray[end - i][j];
- }
- }
- return anotherArray;
- }
- private static int[][] reflectY(int[][] anArray) {
- int i, j, k, l, n, end;
- int[][] anotherArray;
- n = anArray.length;
- anotherArray = new int[n][n];
- end = n - 1;
- for (i = 0; i < n; i++){
- for (j = 0; j < n; j++){
- anotherArray[i][j] = anArray[i][end - j];
- }
- }
- return anotherArray;
- }
- public static int[][] operate(String operation, String type, int[][] anArray) {
- int[][] anotherArray;
- anotherArray = new int[anArray.length][anArray.length];
- if (operation.equals("Rotate")){
- anotherArray = rotate(type, anArray);
- } else if (operation.equals("Reflect")){
- if (type.equals("x")){
- anotherArray = reflectX(anArray);
- } else if (type.equals("y")){
- anotherArray = reflectY(anArray);
- }
- }
- return anotherArray;
- }
- }
- class Transformation {
- public static void main(String[] args) {
- Scanner myScanner = new Scanner(System.in);
- int firstCheck, secondCheck;
- firstCheck = myScanner.nextInt();
- int[][] anArray;
- anArray = new int[firstCheck][firstCheck];
- for (int j = 0; j < firstCheck; j++){
- for (int k = 0; k < firstCheck; k++){
- int a;
- a = myScanner.nextInt();
- anArray[j][k] = a;
- }
- }
- secondCheck = myScanner.nextInt();
- String thirdCheck, fourthCheck;
- for (int i = 0; i < secondCheck; i++){
- thirdCheck = myScanner.next();
- fourthCheck = myScanner.next();
- anArray = Matrix.operate(thirdCheck, fourthCheck, anArray);
- }
- for (int a = 0; a < firstCheck; a++){
- for (int b = 0; b < firstCheck; b++){
- System.out.print(anArray[a][b]);
- if (b < firstCheck - 1){
- System.out.print(" ");
- }
- }
- if (a < firstCheck - 1){
- System.out.println("");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment