Advertisement
deyanmalinov

06. String Matrix Rotation

May 25th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1. package DPM;
  2. import java.util.ArrayList;
  3. import java.util.Scanner;
  4. public class Main {
  5.     public static void main(String[] args){
  6.         Scanner scan = new Scanner(System.in);
  7.         String[] rotate = scan.nextLine().split("[ () ]+");
  8.         int angle = Integer.parseInt(rotate[1]) % 360;
  9.         ArrayList<String> array = new ArrayList<>();
  10.         String line = scan.nextLine();
  11.         int maxLen = line.length();
  12.  
  13.         while (!line.equals("END")){
  14.             array.add(line);
  15.             line = scan.nextLine();
  16.  
  17.             if (maxLen < line.length()){
  18.                 maxLen = line.length();
  19.             }
  20.         }
  21.         char[][] matrix = new char[array.size()][maxLen];
  22.         for (int row = 0; row < array.size(); row++) {
  23.             for (int col = 0; col < maxLen; col++) {
  24.                 if (col > array.get(row).length() - 1){
  25.                     matrix[row][col] = ' ';
  26.                 }else {
  27.                     matrix[row][col] = array.get(row).charAt(col);
  28.                 }
  29.             }
  30.         }
  31.         if (angle == 90){
  32.             for (int col = 0; col < maxLen; col++) {
  33.                 for (int row = matrix.length -1; row >=0 ; row--) {
  34.                     System.out.print(matrix[row][col]);
  35.                 }
  36.                 System.out.println();
  37.             }
  38.         }else if (angle == 180){
  39.             for (int row = matrix.length-1; row >=0; row--) {
  40.                 for (int col = maxLen -1; col >=0 ; col--) {
  41.                     System.out.print(matrix[row][col]);
  42.                 }
  43.                 System.out.println();
  44.             }
  45.         }else if (angle == 270){
  46.             for (int row = maxLen-1; row >=0; row--) {
  47.                 for (int col = 0; col <matrix.length ; col++) {
  48.                     System.out.print(matrix[col][row]);
  49.                 }
  50.                 System.out.println();
  51.             }
  52.         }else {
  53.             for (int row = 0; row < matrix.length; row++) {
  54.                 for (int col = 0; col < maxLen ; col++) {
  55.                     System.out.print(matrix[row][col]);
  56.                 }
  57.                 System.out.println();
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement