Advertisement
Guest User

NikuldenCharity

a guest
Dec 20th, 2019
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _02Nikulden
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. string input = Console.ReadLine();
  10.  
  11. string[] command = Console.ReadLine()
  12. .Split();
  13.  
  14. while (true)
  15. {
  16. string commandD = command[0];
  17.  
  18. if (commandD == "Replace" && input.Length > 0)
  19. {
  20. char oldOne = char.Parse(command[1]);
  21. char newOne = char.Parse(command[2]);
  22.  
  23. input = input.Replace(oldOne, newOne);
  24. Console.WriteLine(input);
  25. }
  26. else if (commandD == "Cut" && input.Length > 0)
  27. {
  28. int startInx = int.Parse(command[1]);
  29. int endInx = int.Parse(command[2]);
  30.  
  31. if (startInx >= 0 && endInx >= 0 && endInx <= input.Length - 1)
  32. {
  33. input = input.Remove(startInx, endInx);
  34. Console.WriteLine(input);
  35. }
  36. else
  37. {
  38. Console.WriteLine("Invalid indexes!");
  39. }
  40. }
  41. else if (commandD == "Make" && input.Length > 0)
  42. {
  43. if (command[1] == "Upper")
  44. {
  45. input = input.ToUpper();
  46. Console.WriteLine(input);
  47. }
  48. else if (command[1] == "Lower")
  49. {
  50. input = input.ToLower();
  51. Console.WriteLine(input);
  52. }
  53. }
  54. else if (commandD == "Check" && input.Length > 0)
  55. {
  56. string checkwith = command[1];
  57. if (input.Contains(checkwith))
  58. {
  59. Console.WriteLine($"Message contains {checkwith}");
  60. }
  61. else
  62. {
  63. Console.WriteLine($"Message doesn't contain {checkwith}");
  64. }
  65.  
  66.  
  67. }
  68. else if (commandD == "Sum" && input.Length > 0)
  69. {
  70. int S = int.Parse(command[1]);
  71. int E = int.Parse(command[2]);
  72. int total = E - S;
  73. int totalSum = 0;
  74.  
  75. if (S >= 0 && E <= input.Length - 1)
  76. {
  77. string Subbed = input.Substring(S, total + 1);
  78.  
  79. for (int i = Subbed.Length - 1; i >= 0; i--)
  80. {
  81. char ch = Subbed[i];
  82. totalSum += ch;
  83. }
  84. Console.WriteLine(totalSum);
  85. }
  86. else
  87. {
  88. Console.WriteLine($"Invalid indexes!");
  89. }
  90. }
  91. else if (commandD == "Finish")
  92. {
  93. break;
  94. }
  95.  
  96. command = Console.ReadLine()
  97. .Split();
  98.  
  99.  
  100. }
  101. }
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement