Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.80 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. public class kur {
  8.     public static void main(String[] args) throws IOException {
  9.  
  10.         BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
  11.  
  12.         int angle = Integer.parseInt(buffer.readLine().replaceAll("[A-Za-z()]+", "")) % 360;
  13.         String input;
  14.         int maxLength = -1;
  15.         List<String> inputLines = new ArrayList<>();
  16.  
  17.         while (!"END".equals(input = buffer.readLine())) {
  18.  
  19.             inputLines.add(input);
  20.             if (input.length() > maxLength) {
  21.                 maxLength = input.length();
  22.             }
  23.         }
  24.         char[][] matrix = new char[inputLines.size()][maxLength];
  25.  
  26.         for (int i = 0; i < inputLines.size(); i++) {
  27.             for (int j = 0; j < maxLength; j++) {
  28.                
  29.                 if (j < inputLines.get(i).length()) {
  30.                     matrix[i][j] = inputLines.get(i).charAt(j);
  31.                 }else {
  32.                     matrix[i][j] = ' ';
  33.                 }
  34.             }
  35.         }
  36.         matrix = matrixRotation(matrix, angle);
  37.         for (char[] chars : matrix) {
  38.             for (int j = 0; j < matrix[0].length; j++) {
  39.                 System.out.print(chars[j]);
  40.             }
  41.             System.out.println();
  42.         }
  43.     }
  44.     private static char[][] matrixRotation(char[][] matrix, int angle) {
  45.  
  46.         char[][] rotatedMatrix = new char[matrix[0].length][matrix.length];
  47.         int rows = rotatedMatrix.length;
  48.         int cols = rotatedMatrix[0].length;
  49.  
  50.         switch (angle) {
  51.             case 90:
  52.                 for (int i = 0; i < rows; i++) {
  53.                     for (int j = 0; j < cols; j++) {
  54.                         rotatedMatrix[i][j] = matrix[rotatedMatrix[0].length - 1 - j][i];
  55.                     }
  56.                 }
  57.                 break;
  58.             case 180:
  59.                 rotatedMatrix = new char[matrix.length][matrix[0].length];
  60.                 rows = rotatedMatrix.length;
  61.                 cols = rotatedMatrix[0].length;
  62.  
  63.                 for (int i = 0; i < rows; i++) {
  64.                     for (int j = 0; j < cols; j++) {
  65.                         rotatedMatrix[i][j] = matrix[matrix.length - 1 - i][matrix[0].length - 1 - j];
  66.                     }
  67.                 }
  68.                 break;
  69.             case 270:
  70.                 for (int i = 0; i < rows; i++) {
  71.                     for (int j = 0; j < cols; j++) {
  72.                         rotatedMatrix[i][j] = matrix[j][matrix[0].length - 1 - i];
  73.                     }
  74.                 }
  75.                 break;
  76.             default:
  77.                 rotatedMatrix = matrix;
  78.                 break;
  79.         }
  80.         return rotatedMatrix;
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement