RGAlex

O1. TheImitation Game / FinalExam - O1

Mar 16th, 2021
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. package FinalExam.O1;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class O1TheImitationGame {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         StringBuilder input = new StringBuilder(scanner.nextLine());
  9.         String command = scanner.nextLine();
  10.  
  11.         while (!command.equals("Decode")) {
  12.             String[] type = command.split("\\|");
  13.             switch (type[0]) {
  14.                 case "Insert":
  15.                     input.insert(Integer.parseInt(type[1]), type[2]);
  16.                     break;
  17.                 case "ChangeAll":
  18.                     input = new StringBuilder(input.toString().replace(type[1], type[2]));
  19.                     break;
  20.                 case"Move":
  21.                     input = new StringBuilder(input.substring(Integer.parseInt(type[1])) +
  22.                             input.substring(0, Integer.parseInt(type[1])));
  23.                     break;
  24.             }
  25.             command = scanner.nextLine();
  26.         }
  27.         System.out.println("The decrypted message is: " + input);
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment