Advertisement
Guest User

Untitled

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