Advertisement
parunowaa

01.World_Tour

Dec 10th, 2021 (edited)
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.24 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _01.World_Tour
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.  
  11.             string travelStops = Console.ReadLine();
  12.             string instructions = Console.ReadLine();
  13.             string message = travelStops;
  14.  
  15.             while (instructions != "Travel")
  16.             {
  17.                 string[] cmd = instructions.Split(':').ToArray();
  18.                 var cmd1 = cmd[0]; //Add Stop
  19.                 var cmd2 = cmd[1]; //7
  20.                 var cmd3 = cmd[2]; //Rome
  21.  
  22.                 if (cmd1 == "Add Stop")
  23.                 {
  24.                     if (int.Parse(cmd2) >= 0 && int.Parse(cmd2) <= message.Length - 1)
  25.                     {
  26.                         string editedString = message.Insert(int.Parse(cmd2), cmd3);
  27.                         message = editedString;
  28.                         Console.WriteLine(message);
  29.                     }
  30.                     else
  31.                     {
  32.                         Console.WriteLine(message);
  33.                     }
  34.                 }
  35.  
  36.                 if (cmd1 == "Remove Stop")
  37.                 {
  38.                     if ( int.Parse(cmd3) >= 0 && int.Parse(cmd3) <= message.Length - 1)
  39.                     {
  40.                         string editedString = message.Remove(int.Parse(cmd2), int.Parse(cmd3) - int.Parse(cmd2) + 1);
  41.                         message = editedString;
  42.                         Console.WriteLine(message);
  43.                     }
  44.                     else
  45.                     {
  46.                         Console.WriteLine(message);
  47.                     }
  48.                 }
  49.  
  50.                 if (cmd1 == "Switch")
  51.                 {
  52.                     if (message.Contains(cmd2))
  53.                     {
  54.                         string editedString = message.Replace(cmd2, cmd3);
  55.                         message = editedString;
  56.                         Console.WriteLine(message);
  57.                     }
  58.                     else
  59.                     {
  60.                         Console.WriteLine(message);
  61.                     }
  62.                 }
  63.                 instructions = Console.ReadLine();
  64.             }
  65.             Console.WriteLine($"Ready for world tour! Planned stops: {message}");
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement