LardaX

Plus-Remove

Jan 23rd, 2017
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.34 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.Scanner;
  4.  
  5. public class PlusRemoveTests {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         ArrayList<ArrayList<String>> matrix = new ArrayList<>();
  10.  
  11.         String commandLine = scanner.nextLine();
  12.  
  13.         while (!commandLine.equals("END")) {
  14.             ArrayList<String> currentLine = new ArrayList<>();
  15.  
  16.             for (int i = 0; i < commandLine.length(); i++) {
  17.                 currentLine.add(String.valueOf(commandLine.charAt(i)));
  18.             }
  19.  
  20.             matrix.add(currentLine);
  21.  
  22.             commandLine = scanner.nextLine();
  23.         }
  24.  
  25.         ArrayList<int[]> indexes = new ArrayList<>();
  26.  
  27.         for (int row = 0; row < matrix.size() - 2; row++) {
  28.             for (int col = 1; col < matrix.get(row).size(); col++) {
  29.                 String currentChar = matrix.get(row).get(col);
  30.  
  31.                 try {
  32.  
  33.                     if (!"".equals(currentChar)
  34.                             && matrix.get(row).get(col).toLowerCase().equals(matrix.get(row + 1).get(col - 1).toLowerCase())
  35.                             && matrix.get(row).get(col).toLowerCase().equals(matrix.get(row + 1).get(col).toLowerCase())
  36.                             && matrix.get(row).get(col).toLowerCase().equals(matrix.get(row + 1).get(col + 1).toLowerCase())
  37.                             && matrix.get(row).get(col).toLowerCase().equals(matrix.get(row + 2).get(col).toLowerCase())) {
  38.                         indexes.add(new int[]{row, col});
  39.                         indexes.add(new int[]{row + 1, col - 1});
  40.                         indexes.add(new int[]{row + 1, col});
  41.                         indexes.add(new int[]{row + 1, col + 1});
  42.                         indexes.add(new int[]{row + 2, col});
  43.  
  44.                     }
  45.                 } catch (Exception error) {
  46.  
  47.                 }
  48.             }
  49.         }
  50.  
  51.             for (int[] index : indexes) {
  52.                 matrix.get(index[0]).set(index[1], "");
  53.             }
  54.  
  55.             for (ArrayList<String> strings : matrix) {
  56.                 for (String string : strings) {
  57.                     if (!string.isEmpty()) {
  58.                         System.out.print(string);
  59.                     }
  60.                 }
  61.                 System.out.println();
  62.             }
  63.         }
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment