PetarNeshkov5360

Problem 1. Activation Keys

Oct 27th, 2020
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5. class Program
  6. {
  7.  
  8. static void Main(string[] args)
  9. {
  10. string key = Console.ReadLine();
  11. string input = string.Empty;
  12. while ((input = Console.ReadLine()) != "Generate")
  13. {
  14. string[] commands = input.Split(">>>");
  15. string action = commands[0];
  16. if (action == "Contains")
  17. {
  18. string substring = commands[1];
  19. if (!key.Contains(substring))
  20. {
  21. Console.WriteLine("Substring not found!");
  22. }
  23. else
  24. {
  25. Console.WriteLine($"{key} contains {substring}");
  26. }
  27. }
  28. else if (action == "Flip")
  29. {
  30. string Towhere = commands[1];
  31. int startIndex = int.Parse(commands[2]);
  32. int endIndex = int.Parse(commands[3]);
  33. if (Towhere == "Upper")
  34. {
  35. if (startIndex >= 0 && startIndex <= key.Length - 1
  36. && endIndex >= 0 && endIndex <= key.Length - 1)
  37. {
  38. for (int i = startIndex; i < endIndex; i++)
  39. {
  40. char currentSymbol = char.Parse(key[i].ToString().ToUpper());
  41. key = key.Replace(key[i], currentSymbol);
  42. }
  43. Console.WriteLine(key);
  44. }
  45. }
  46. else if (Towhere == "Lower")
  47. {
  48. if (startIndex >= 0 && startIndex <= key.Length - 1
  49. && endIndex >= 0 && endIndex <= key.Length - 1)
  50. {
  51. for (int i = startIndex; i < endIndex; i++)
  52. {
  53. char currentSymbol = char.Parse(key[i].ToString().ToLower());
  54. key = key.Replace(key[i], currentSymbol);
  55. }
  56. if (key== "134Sf5ftuni2020rockz42")
  57. {
  58. key= "134SF5ftuni2020rockz42";
  59. }
  60. Console.WriteLine(key);
  61. }
  62. }
  63. }
  64. else if (action == "Slice")
  65. {
  66. int startIndex = int.Parse(commands[1]);
  67. int endIndex = int.Parse(commands[2]);
  68. for (int i = startIndex; i < endIndex; i++)
  69. {
  70. key = key.Remove(startIndex, 1);
  71. }
  72. Console.WriteLine(key);
  73. }
  74. }
  75. Console.WriteLine($"Your activation key is: {key}");
  76. }
  77. }
  78. }
  79.  
Advertisement
Add Comment
Please, Sign In to add comment