Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] command = scanner.nextLine().split("Rotate\\(|\\)");
- int rotation = Integer.parseInt(command[1]);
- while (rotation >= 360) {
- rotation -= 360;
- }
- rotation = rotation / 90;
- //Razbiram kolko shte bude zavurtqna matricata
- String input = "";
- int count = 0;
- List<String> str = new ArrayList<>();
- int length = 0;
- while (!"END".equals(input = scanner.nextLine())) {
- str.add(input);
- count++;
- if (input.length() > length) {
- length = input.length();
- }
- }
- //2. Count i Length izpolzvam za da znam (x , y) kolko na kolko shte bude golqma
- char[][] matrix = new char[count][length];
- for (int i = 0; i < count; i++) {
- String x = str.get(i);
- char y;
- for (int j = 0; j < length; j++) {
- if (j >= x.length()) {
- y = ' '; //2.1 slagam space za da bude ravna matrica
- } else {
- y = x.charAt(j);
- }
- matrix[i][j] = y;
- }
- }
- //3. Pulnq veche orazmerenata matrica
- switch (rotation) {
- case 0:
- for (char[] chars : matrix) {
- System.out.println(Arrays.toString(chars).replaceAll("[\\[\\], ]", ""));
- }
- break;
- case 1:
- for (int col = 0; col < length; col++) {
- String print = "";
- for (int row = count - 1; row >= 0; row--) {
- print += matrix[row][col];
- }
- System.out.println(print);
- }
- break;
- case 2:
- for (int row = count - 1; row >= 0; row--) {
- String print = "";
- for (int col = length - 1; col >= 0; col--) {
- print += matrix[row][col];
- }
- System.out.println(print);
- }
- break;
- case 3:
- for (int col = length-1; col >= 0; col--) {
- String print = "";
- for (int row = 0; row < count; row++) {
- print += matrix[row][col];
- }
- System.out.println(print);
- }
- break;
- }
- //4. Printiram spored tova kak trqbva da bude zavurtqna
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement