Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class FireArrows {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = Integer.parseInt(sc.nextLine());
- String line = sc.nextLine();
- char[][] matrix = new char[n][line.length()];
- for (int row = 0; row < n; row++) {
- for (int col = 0; col < line.length(); col++) {
- matrix[row][col] = line.charAt(col);
- }
- if(row<n-1) {
- line = sc.nextLine();
- }
- }
- boolean moved = true;
- while (moved) {
- moved = false;
- for (int row = 0; row < matrix.length; row++) {
- for (int col = 0; col < matrix[row].length; col++) {
- char current = matrix[row][col];
- switch (current) {
- case 'v':
- if (row != matrix.length - 1) {
- if (matrix[row + 1][col] == 'o') {
- matrix[row + 1][col] = 'v';
- matrix[row][col] = 'o';
- moved = true;
- }
- }
- break;
- case '^':
- if (row != 0) {
- if (matrix[row - 1][col] == 'o') {
- matrix[row - 1][col] = '^';
- matrix[row][col] = 'o';
- moved = true;
- }
- }
- break;
- case '<':
- if (col != 0) {
- if (matrix[row][col - 1] == 'o') {
- matrix[row][col - 1] = '<';
- matrix[row][col] = 'o';
- moved = true;
- }
- }
- break;
- case '>':
- if (col != matrix[0].length - 1) {
- if (matrix[row][col + 1] == 'o') {
- matrix[row][col + 1] = '>';
- matrix[row][col] = 'o';
- col++;
- moved = true;
- }
- }
- break;
- }
- }
- }
- }
- for (char[] row : matrix) {
- for (char col : row) {
- System.out.print("" + col);
- }
- System.out.println();
- }
- }
- }
Add Comment
Please, Sign In to add comment