RGAlex

O3. Text Processing / Text Processing - More Exercise

Mar 15th, 2021
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. package TextPlocessing.MoreExercises;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5.  
  6. public class O3TextProcessing {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         int[] key = Arrays.stream(scanner.nextLine().split(" "))
  10.                 .mapToInt(Integer::parseInt)
  11.                 .toArray();
  12.         String input = scanner.nextLine();
  13.  
  14.         while (!"find".equals(input)) {
  15.             StringBuilder output = new StringBuilder();
  16.             int count = 0;
  17.             for (int i = 0; i < input.length(); i++) {
  18.                 if (count == key.length) {
  19.                     count = 0;
  20.                 }
  21.                 output.append((char) (input.charAt(i) - key[count]));
  22.                 count++;
  23.             }
  24.             System.out.printf("Found %s at %s%n", output.substring(output.indexOf("&") + 1, output.lastIndexOf("&"))
  25.                     , output.substring(output.indexOf("<") + 1, output.lastIndexOf(">")));
  26.  
  27.             input = scanner.nextLine();
  28.         }
  29.     }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment