Guest User

Untitled

a guest
Apr 14th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.84 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FireArrows {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.         int n = Integer.parseInt(sc.nextLine());
  7.         String line = sc.nextLine();
  8.         char[][] matrix = new char[n][line.length()];
  9.         for (int row = 0; row < n; row++) {
  10.             for (int col = 0; col < line.length(); col++) {
  11.                 matrix[row][col] = line.charAt(col);
  12.             }
  13.             if(row<n-1) {
  14.                 line = sc.nextLine();
  15.             }
  16.         }
  17.         boolean moved = true;
  18.         while (moved) {
  19.             moved = false;
  20.             for (int row = 0; row < matrix.length; row++) {
  21.                 for (int col = 0; col < matrix[row].length; col++) {
  22.                     char current = matrix[row][col];
  23.                     switch (current) {
  24.                         case 'v':
  25.                             if (row != matrix.length - 1) {
  26.                                 if (matrix[row + 1][col] == 'o') {
  27.                                     matrix[row + 1][col] = 'v';
  28.                                     matrix[row][col] = 'o';
  29.                                     moved = true;
  30.                                 }
  31.                             }
  32.                             break;
  33.                         case '^':
  34.                             if (row != 0) {
  35.                                 if (matrix[row - 1][col] == 'o') {
  36.                                     matrix[row - 1][col] = '^';
  37.                                     matrix[row][col] = 'o';
  38.                                     moved = true;
  39.                                 }
  40.                             }
  41.                             break;
  42.                         case '<':
  43.                             if (col != 0) {
  44.                                 if (matrix[row][col - 1] == 'o') {
  45.                                     matrix[row][col - 1] = '<';
  46.                                     matrix[row][col] = 'o';
  47.                                     moved = true;
  48.                                 }
  49.                             }
  50.                             break;
  51.                         case '>':
  52.                             if (col != matrix[0].length - 1) {
  53.                                 if (matrix[row][col + 1] == 'o') {
  54.                                     matrix[row][col + 1] = '>';
  55.                                     matrix[row][col] = 'o';
  56.                                     col++;
  57.                                     moved = true;
  58.                                 }
  59.                             }
  60.                             break;
  61.                     }
  62.                 }
  63.             }
  64.         }
  65.  
  66.         for (char[] row : matrix) {
  67.             for (char col : row) {
  68.                 System.out.print("" + col);
  69.             }
  70.             System.out.println();
  71.         }
  72.     }
  73. }
Add Comment
Please, Sign In to add comment