Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class ActivationKeysSolutionSB {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- //The first line of the input will be your raw activation key.
- String input = scanner.nextLine();
- StringBuilder sb = new StringBuilder(input);
- //Until the "Generate" command is given, you will be receiving strings with instructions.
- String command = scanner.nextLine();
- while (!command.equals("Generate")) {
- //Contains checks if the raw activation key contains the given substring.
- if (command.split(">>>")[0].equals("Contains")) {
- String substring = command.split(">>>")[1];
- //If it contains the given substring prints: "{raw activation key} contains {substring}".
- //If not, prints: "Substring not found!"
- if (sb.toString().contains(substring)) {
- System.out.printf("%s contains %s%n", input, substring);
- } else {
- System.out.println("Substring not found!");
- }
- //Flip changes the substring between the given indices to upper or lower case.
- } else if (command.split(">>>")[0].equals("Flip")) {
- //Case Upper.
- if (command.split(">>>")[1].equals("Upper")) {
- //All given indexes will be valid.
- int startIndex = Integer.parseInt(command.split(">>>")[2]);
- int endIndex = Integer.parseInt(command.split(">>>")[3]);
- //Replace process
- String upperCase = sb.substring(startIndex, endIndex).toUpperCase();
- sb.replace(startIndex, endIndex, upperCase);
- input = sb.toString();
- //Prints the activation key.
- System.out.println(input);
- //Case Lower.
- } else if (command.split(">>>")[1].equals("Lower")) {
- //All given indexes will be valid.
- int startIndex = Integer.parseInt(command.split(">>>")[2]);
- int endIndex = Integer.parseInt(command.split(">>>")[3]);
- //Replace process.
- String upperCase = sb.substring(startIndex, endIndex).toLowerCase();
- sb.replace(startIndex, endIndex, upperCase);
- input = sb.toString();
- //Prints the activation key.
- System.out.println(input);
- }
- //Slice deletes the characters between the start and end indices.
- } else if (command.split(">>>")[0].equals("Slice")) {
- //Both indices will be valid.
- int startIndex = Integer.parseInt(command.split(">>>")[1]);
- int endIndex = Integer.parseInt(command.split(">>>")[2]);
- // Remove process.
- sb.replace(startIndex, endIndex, "");
- input = sb.toString();
- //Prints the activation key.
- System.out.println(input);
- }
- //Update command line.
- command = scanner.nextLine();
- }
- //After the "Generate" command is received.
- System.out.printf("Your activation key is: %s", input);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement