Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- namespace _01._World_Tour
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- StringBuilder sb = new StringBuilder();
- sb.Append(input);
- string cmd = Console.ReadLine();
- while (cmd != "Travel")
- {
- string[] command = cmd.Split(':', StringSplitOptions.RemoveEmptyEntries);
- if (command[0] == "Add Stop")
- {
- int index = int.Parse(command[1]);
- string place = command[2];
- if (index >= 0 && index < sb.Length)
- {
- sb.Insert(index, place);
- }
- Console.WriteLine(sb);
- }
- else if (command[0] == "Remove Stop")
- {
- int startIndex = int.Parse(command[1]);
- int endIndex = int.Parse(command[2]);
- if ((startIndex >= 0 && startIndex < sb.Length) && (endIndex < sb.Length && endIndex >= 0) && (startIndex <= endIndex))
- {
- sb.Remove(startIndex, (endIndex + 1) - startIndex);
- }
- Console.WriteLine(sb);
- }
- else if (command[0] == "Switch")
- {
- string oldString = command[1];
- string newString = command[2];
- if (sb.ToString().Contains(oldString) && oldString != newString)
- {
- sb.Replace(oldString, newString);
- }
- Console.WriteLine(sb);
- }
- cmd = Console.ReadLine();
- }
- Console.WriteLine($"Ready for world tour! Planned stops: {sb}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement