Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace WorldTour
- {
- class Program
- {
- static void Main(string[] args)
- {
- string initialString = Console.ReadLine();
- string command = string.Empty;
- while ((command = Console.ReadLine()) != "Travel")
- {
- string[] commandArray = command.Split(':');
- if (commandArray[0] == "Add Stop")
- {
- int index = int.Parse(commandArray[1]);
- string text = commandArray[2];
- if (index >= 0 && index <= initialString.Length)
- {
- initialString = initialString.Insert(index, text);
- }
- Console.WriteLine(initialString);
- }
- else if (commandArray[0] == "Remove Stop")
- {
- int startIndex = int.Parse(commandArray[1]);
- int endIndex = int.Parse(commandArray[2]);
- if ((startIndex >= 0 && startIndex <= initialString.Length-1) && (endIndex >= 0 && endIndex <= initialString.Length-1) && startIndex <= endIndex)
- {
- int length = endIndex - startIndex + 1;
- initialString = initialString.Remove(startIndex, length);
- }
- Console.WriteLine(initialString);
- }
- else if (commandArray[0] == "Switch")
- {
- string oldString = commandArray[1];
- string newString = commandArray[2];
- if (initialString.Contains(oldString) && oldString != newString)// Replace whithout while loop
- {
- initialString = initialString.Replace(oldString, newString);
- }
- Console.WriteLine(initialString);
- }
- }
- Console.WriteLine($"Ready for world tour! Planned stops: {initialString}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement