Advertisement
CR7CR7

ack

Dec 1st, 2022
1,163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.40 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class ActivationKeysSolutionSB {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         //The first line of the input will be your raw activation key.
  8.         String input = scanner.nextLine();
  9.  
  10.         StringBuilder sb = new StringBuilder(input);
  11.  
  12.         //Until the "Generate" command is given, you will be receiving strings with instructions.
  13.         String command = scanner.nextLine();
  14.  
  15.         while (!command.equals("Generate")) {
  16.  
  17.             //Contains checks if the raw activation key contains the given substring.
  18.             if (command.split(">>>")[0].equals("Contains")) {
  19.                 String substring = command.split(">>>")[1];
  20.  
  21.                 //If it contains the given substring prints: "{raw activation key} contains {substring}".
  22.                 //If not, prints: "Substring not found!"
  23.                 if (sb.toString().contains(substring)) {
  24.                     System.out.printf("%s contains %s%n", input, substring);
  25.                 } else {
  26.                     System.out.println("Substring not found!");
  27.                 }
  28.  
  29.                 //Flip changes the substring between the given indices to upper or lower case.
  30.             } else if (command.split(">>>")[0].equals("Flip")) {
  31.  
  32.                 //Case Upper.
  33.                 if (command.split(">>>")[1].equals("Upper")) {
  34.  
  35.                     //All given indexes will be valid.
  36.                     int startIndex = Integer.parseInt(command.split(">>>")[2]);
  37.                     int endIndex = Integer.parseInt(command.split(">>>")[3]);
  38.  
  39.                     //Replace process
  40.                     String upperCase = sb.substring(startIndex, endIndex).toUpperCase();
  41.                     sb.replace(startIndex, endIndex, upperCase);
  42.                     input = sb.toString();
  43.  
  44.                     //Prints the activation key.
  45.                     System.out.println(input);
  46.  
  47.                     //Case Lower.
  48.                 } else if (command.split(">>>")[1].equals("Lower")) {
  49.  
  50.                     //All given indexes will be valid.
  51.                     int startIndex = Integer.parseInt(command.split(">>>")[2]);
  52.                     int endIndex = Integer.parseInt(command.split(">>>")[3]);
  53.  
  54.                     //Replace process.
  55.                     String upperCase = sb.substring(startIndex, endIndex).toLowerCase();
  56.                     sb.replace(startIndex, endIndex, upperCase);
  57.                     input = sb.toString();
  58.  
  59.                     //Prints the activation key.
  60.                     System.out.println(input);
  61.                 }
  62.  
  63.                 //Slice deletes the characters between the start and end indices.
  64.             } else if (command.split(">>>")[0].equals("Slice")) {
  65.  
  66.                 //Both indices will be valid.
  67.                 int startIndex = Integer.parseInt(command.split(">>>")[1]);
  68.                 int endIndex = Integer.parseInt(command.split(">>>")[2]);
  69.  
  70.                 // Remove process.
  71.                 sb.replace(startIndex, endIndex, "");
  72.                 input = sb.toString();
  73.  
  74.                 //Prints the activation key.
  75.                 System.out.println(input);
  76.             }
  77.             //Update command line.
  78.             command = scanner.nextLine();
  79.         }
  80.  
  81.         //After the "Generate" command is received.
  82.         System.out.printf("Your activation key is: %s", input);
  83.     }
  84. }
  85.  
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement