Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.82 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.            
  28.             for (int j = 0; j < maxLength; j++) {
  29.                
  30.                 if (j < inputLines.get(i).length()) {
  31.                     matrix[i][j] = inputLines.get(i).charAt(j);
  32.                 }else {
  33.                     matrix[i][j] = ' ';
  34.                 }
  35.             }
  36.         }
  37.         matrix = matrixRotation(matrix, angle);
  38.         for (char[] chars : matrix) {
  39.             for (int j = 0; j < matrix[0].length; j++) {
  40.                 System.out.print(chars[j]);
  41.             }
  42.             System.out.println();
  43.         }
  44.     }
  45.     private static char[][] matrixRotation(char[][] matrix, int angle) {
  46.  
  47.         char[][] rotatedMatrix = new char[matrix[0].length][matrix.length];
  48.         int rows = rotatedMatrix.length;
  49.         int cols = rotatedMatrix[0].length;
  50.  
  51.         switch (angle) {
  52.             case 90:
  53.                 for (int i = 0; i < rows; i++) {
  54.  
  55.                     for (int j = 0; j < cols; j++) {
  56.                         rotatedMatrix[i][j] = matrix[rotatedMatrix[0].length - 1 - j][i];
  57.                     }
  58.                 }
  59.                 break;
  60.             case 180:
  61.                 rotatedMatrix = new char[matrix.length][matrix[0].length];
  62.                 rows = rotatedMatrix.length;
  63.                 cols = rotatedMatrix[0].length;
  64.  
  65.                 for (int i = 0; i < rows; i++) {
  66.  
  67.                     for (int j = 0; j < cols; j++) {
  68.                         rotatedMatrix[i][j] = matrix[matrix.length - 1 - i][matrix[0].length - 1 - j];
  69.                     }
  70.                 }
  71.                 break;
  72.             case 270:
  73.                 for (int i = 0; i < rows; i++) {
  74.  
  75.                     for (int j = 0; j < cols; j++) {
  76.                         rotatedMatrix[i][j] = matrix[j][matrix[0].length - 1 - i];
  77.                     }
  78.                 }
  79.                 break;
  80.             default:
  81.                 rotatedMatrix = matrix;
  82.                 break;
  83.         }
  84.         return rotatedMatrix;
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement