Advertisement
Guest User

Untitled

a guest
Aug 9th, 2020
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7.  
  8. namespace Problem_1
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. string input = Console.ReadLine();
  15.  
  16. string command = Console.ReadLine();
  17.  
  18. while (command != "Travel")
  19. {
  20. string[] splitted = command.Split(':');
  21.  
  22. if (command.Contains("Add Stop"))
  23. {
  24. int index = int.Parse(splitted[1]);
  25. string toAdd = splitted[2];
  26.  
  27. if (index >= 0 && index < input.Length)
  28. {
  29. input = input.Insert(index, toAdd);
  30. }
  31.  
  32. Console.WriteLine(input);
  33. }
  34. else if (command.Contains("Remove Stop"))
  35. {
  36. int startIndex = int.Parse(splitted[1]);
  37. int endIndex = int.Parse(splitted[2]);
  38.  
  39.  
  40. if (startIndex >= 0 && endIndex < input.Length)
  41. {
  42. input = input.Remove(startIndex, endIndex - startIndex +1);
  43. }
  44.  
  45. Console.WriteLine(input);
  46. }
  47. else if (command.Contains("Switch"))
  48. {
  49. string oldString = splitted[1];
  50. string newString = splitted[2];
  51.  
  52. if (input.Contains(oldString))
  53. {
  54. input = input.Replace(oldString, newString);
  55. }
  56.  
  57. Console.WriteLine(input);
  58. }
  59.  
  60. command = Console.ReadLine();
  61. }
  62.  
  63. Console.WriteLine($"Ready for world tour! Planned stops: {input}");
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement