osman1997

01. problem Final exam 13 dec 2020

Dec 13th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6.  
  7.  
  8. class Program
  9. {
  10.  
  11. static void Main()
  12. {
  13. var input = Console.ReadLine();
  14.  
  15. string command = Console.ReadLine();
  16.  
  17. while (command != "End")
  18. {
  19. string[] line = command.Split();
  20. string cmd = line[0];
  21.  
  22. if (cmd == "Translate")
  23. {
  24. var oldChar = line[1];
  25. var newChar = line[2];
  26.  
  27. input = input.Replace(oldChar, newChar);
  28. Console.WriteLine(input);
  29. }
  30. else if (cmd == "Includes")
  31. {
  32. string isContains = line[1];
  33.  
  34. if (input.Contains(isContains))
  35. {
  36. Console.WriteLine("True");
  37. }
  38. else
  39. {
  40. Console.WriteLine("False");
  41. }
  42. }
  43. else if (cmd == "Lowercase")
  44. {
  45. input = input.ToLower();
  46.  
  47. Console.WriteLine(input);
  48. }
  49. else if (cmd == "FindIndex")
  50. {
  51. var index = line[1];
  52. int indexOf = input.LastIndexOf(index);
  53. Console.WriteLine(indexOf);
  54. }
  55. else if (cmd == "Start")
  56. {
  57. StringBuilder sb = new StringBuilder();
  58. string isSame = line[1];
  59.  
  60. bool isTrue = true;
  61.  
  62. while (isTrue)
  63. {
  64. for (int i = 0; i < input.Length; i++)
  65. {
  66. var diff = input[i].ToString();
  67. if(diff == " ")
  68. {
  69. isTrue = false;
  70. break;
  71. }
  72. else if(diff != " ")
  73. {
  74. sb.Append(diff);
  75. }
  76. }
  77. }
  78.  
  79. if(isSame == sb.ToString())
  80. {
  81. Console.WriteLine("True");
  82. }
  83. else
  84. {
  85. Console.WriteLine("False");
  86. }
  87. }
  88. else if (cmd == "Remove")
  89. {
  90. int startIndex = int.Parse(line[1]);
  91. int endIndex = int.Parse(line[2]);
  92.  
  93.  
  94. input = input.Remove(startIndex, endIndex);
  95.  
  96. Console.WriteLine(input);
  97. }
  98.  
  99.  
  100. command = Console.ReadLine();
  101. }
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment