petarkobakov

Nikulden's charity

Aug 4th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace Nikulden_s_Charity
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10.  
  11. string result = Console.ReadLine();
  12. int sum = 0;
  13.  
  14. while (true)
  15. {
  16. string [] commands = Console.ReadLine().Split();
  17. string currentCommand = commands[0];
  18.  
  19.  
  20. if (currentCommand == "Finish")
  21. {
  22. break;
  23. }
  24.  
  25. else if (currentCommand == "Replace")
  26. {
  27. char oldValue = char.Parse(commands[1]);
  28. char newValue = char.Parse(commands[2]);
  29.  
  30. result = result.Replace(oldValue, newValue);
  31.  
  32. Console.WriteLine(result);
  33. }
  34.  
  35. else if (currentCommand == "Cut")
  36. {
  37.  
  38. int startIndex = int.Parse(commands[1]);
  39. int endIndex = int.Parse(commands[2]);
  40.  
  41. if (startIndex>=0 && endIndex<= result.Length)
  42. {
  43. int range = endIndex - startIndex;
  44. result = result.Remove(startIndex, range+1);
  45.  
  46. Console.WriteLine(result);
  47. }
  48.  
  49. else
  50. {
  51. Console.WriteLine("Invalid indexes!");
  52. }
  53. }
  54.  
  55. else if (currentCommand == "Make")
  56. {
  57. string upOrDown = commands[1];
  58.  
  59. if (upOrDown == "Upper")
  60. {
  61. result = result.ToUpper();
  62.  
  63. Console.WriteLine(result);
  64. }
  65.  
  66. else if (upOrDown == "Lower")
  67. {
  68. result = result.ToLower();
  69.  
  70. Console.WriteLine(result);
  71. }
  72. }
  73.  
  74. else if (currentCommand == "Check")
  75. {
  76.  
  77. string substring = commands[1];
  78.  
  79. if (result.Contains(substring))
  80. {
  81. Console.WriteLine($"Message contains {substring}");
  82. }
  83.  
  84. else
  85. {
  86. Console.WriteLine($"Message doesn't contain {substring}");
  87. }
  88.  
  89. }
  90.  
  91. else if (currentCommand == "Sum")
  92. {
  93. int startIndex = int.Parse(commands[1]);
  94. int endIndex = int.Parse(commands[2]);
  95.  
  96. if (startIndex >= 0 && endIndex <= result.Length)
  97. {
  98. for (int i = startIndex; i <= endIndex; i++)
  99. {
  100. sum += result[i];
  101. }
  102.  
  103. Console.WriteLine(sum);
  104. }
  105.  
  106. else
  107. {
  108. Console.WriteLine("Invalid indexes!");
  109. }
  110. }
  111. }
  112. }
  113. }
  114. }
  115.  
Advertisement
Add Comment
Please, Sign In to add comment