Advertisement
dragonbs

Activation Keys

Mar 27th, 2023
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. class Program
  5. {
  6.     static void Main()
  7.     {
  8.         string key = Console.ReadLine();
  9.         string input;
  10.         while ((input = Console.ReadLine()) != "Generate")
  11.         {
  12.             string[] cmd = input.Split(">>>");
  13.             switch (cmd[0])
  14.             {
  15.                 case "Contains": Contains(key, cmd[1]); break;
  16.                 case "Flip": key = Flip(key, cmd); break;
  17.                 case "Slice": key = Slice(key, cmd); break;
  18.             }
  19.         }
  20.         Console.WriteLine($"Your activation key is: {key}");
  21.     }
  22.  
  23.     private static void Contains(string key, string substring)
  24.     {
  25.         if (key.Contains(substring))
  26.             Console.WriteLine($"{key} contains {substring}");
  27.         else
  28.             Console.WriteLine("Substring not found!");
  29.     }
  30.  
  31.     private static string Flip(string key, string[] cmd)
  32.     {
  33.         int startIndex = int.Parse(cmd[2]);
  34.         int endIndex = int.Parse(cmd[3]);
  35.         string substring = key.Substring(startIndex, endIndex - startIndex);
  36.         key = key.Remove(startIndex, endIndex - startIndex);
  37.  
  38.         if (cmd[1] == "Upper")
  39.             substring = substring.ToUpper();
  40.         else if (cmd[1] == "Lower")
  41.             substring = substring.ToLower();
  42.  
  43.         key = key.Insert(startIndex, substring);
  44.         Console.WriteLine(key);
  45.         return key;
  46.     }
  47.  
  48.     private static string Slice(string key, string[] cmd)
  49.     {
  50.         int startIndex = int.Parse(cmd[1]);
  51.         int endIndex = int.Parse(cmd[2]);
  52.         key = key.Remove(startIndex, endIndex - startIndex);
  53.         Console.WriteLine(key);
  54.         return key;
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement