Advertisement
Guest User

Problem 1. World Tour

a guest
Aug 14th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1.  
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Text.RegularExpressions;
  7. namespace _6
  8. {
  9. class Program
  10. {
  11.  
  12.  
  13. static void Main(string[] args)
  14. {
  15. string countries = Console.ReadLine();
  16. while (true)
  17. {
  18. string line = Console.ReadLine();
  19. if (line == "Travel")
  20. {
  21. Console.WriteLine($"Ready for world tour! Planned stops: {countries}");
  22. break;
  23. }
  24. string[] tokens = line.Split(":");
  25. switch (tokens[0])
  26. {
  27. case "Switch":
  28. {
  29. string stringToCheck = tokens[1];
  30. string stringToAdd = tokens[2];
  31. bool checkIfItContainsChar = countries.Contains(stringToCheck);
  32. if (checkIfItContainsChar == true)
  33. {
  34. string replacement = countries.Replace(stringToCheck, stringToAdd);
  35. countries = replacement;
  36. Console.WriteLine(countries);
  37. }
  38. else
  39. {
  40.  
  41. }
  42. break;
  43. }
  44. case "Add Stop":
  45. {
  46. int stringToAddIndex = int.Parse(tokens[1]);
  47. string stringToAdd = tokens[2];
  48. if (stringToAddIndex <= countries.Length && stringToAddIndex >= 0)
  49. {
  50. string CutString = countries.Insert(stringToAddIndex, stringToAdd);
  51. countries = CutString;
  52. Console.WriteLine(countries);
  53. }
  54. break;
  55. }
  56. case "Remove Stop":
  57. {
  58. int stringToCutFirstIndex = int.Parse(tokens[1]);
  59. int stringToCutSecondIndex = int.Parse(tokens[2]);
  60.  
  61. if (stringToCutFirstIndex <= countries.Length && stringToCutSecondIndex <= countries.Length && stringToCutSecondIndex >= 0 && stringToCutFirstIndex >= 0)
  62. {
  63. string CutString = countries.Remove(stringToCutFirstIndex, stringToCutSecondIndex - stringToCutFirstIndex + 1);
  64. countries = CutString;
  65. Console.WriteLine(countries);
  66. }
  67. else
  68. {
  69.  
  70. }
  71. break;
  72. }
  73.  
  74.  
  75. }
  76.  
  77.  
  78. }
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement