Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _01.World_Tour
- {
- class Program
- {
- static void Main(string[] args)
- {
- string travelStops = Console.ReadLine();
- string instructions = Console.ReadLine();
- string message = travelStops;
- while (instructions != "Travel")
- {
- string[] cmd = instructions.Split(':').ToArray();
- var cmd1 = cmd[0]; //Add Stop
- var cmd2 = cmd[1]; //7
- var cmd3 = cmd[2]; //Rome
- if (cmd1 == "Add Stop")
- {
- if (int.Parse(cmd2) >= 0 && int.Parse(cmd2) <= message.Length - 1)
- {
- string editedString = message.Insert(int.Parse(cmd2), cmd3);
- message = editedString;
- Console.WriteLine(message);
- }
- else
- {
- Console.WriteLine(message);
- }
- }
- if (cmd1 == "Remove Stop")
- {
- if ( int.Parse(cmd3) >= 0 && int.Parse(cmd3) <= message.Length - 1)
- {
- string editedString = message.Remove(int.Parse(cmd2), int.Parse(cmd3) - int.Parse(cmd2) + 1);
- message = editedString;
- Console.WriteLine(message);
- }
- else
- {
- Console.WriteLine(message);
- }
- }
- if (cmd1 == "Switch")
- {
- if (message.Contains(cmd2))
- {
- string editedString = message.Replace(cmd2, cmd3);
- message = editedString;
- Console.WriteLine(message);
- }
- else
- {
- Console.WriteLine(message);
- }
- }
- instructions = Console.ReadLine();
- }
- Console.WriteLine($"Ready for world tour! Planned stops: {message}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement