Advertisement
KarolPiechaczek

file

Jan 30th, 2022
741
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1.         // gΓ³ra standardowo
  2.         File plik = new File("instrukcje.txt");
  3.         Scanner scan = new Scanner(plik);
  4.         List<String> instructions = new ArrayList<>();
  5.         List<Character> letters = new ArrayList<>();
  6.         String command;
  7.         char character;
  8.         int counter = 0;
  9.         Map<Integer, String> instructionsInRow = new HashMap<>();
  10.        
  11.         while (scan.hasNext()) {
  12.             command = scan.next();
  13.             instructions.add(command);
  14.             character = scan.next().charAt(0);
  15.             letters.add(character);
  16.         }
  17.  
  18.         for (int i = 1; i < instructions.size(); i++) {
  19.             if ((instructions.get(i-1)).equals(instructions.get(i))) {
  20.                 counter++;
  21.                 i++;
  22.                 while ((instructions.get(i-1)).equals(instructions.get(i))) {
  23.                     if ((instructions.get(i)).equals(instructions.get(i+1))) {
  24.                         instructionsInRow.put(counter, instructions.get(i));
  25.                         counter = 0;
  26.                         break;
  27.                     }
  28.                     counter++;
  29.                     i++;
  30.                 }
  31.             }
  32.         }
  33.         System.out.println(instructionsInRow.get(60));
  34.         Set<Integer> keys = instructionsInRow.keySet();
  35.         for (Integer key : keys) {
  36.             System.out.println(key);
  37.         }
  38.        
  39.        
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement