Advertisement
svephoto

World Tour [C#]

Dec 22nd, 2021 (edited)
1,341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.59 KB | None | 0 0
  1. using System;
  2.  
  3. namespace WorldTour
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string input = Console.ReadLine();
  10.             string command = Console.ReadLine();
  11.  
  12.             while (command != "Travel")
  13.             {
  14.                 string[] cmd = command.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
  15.  
  16.                 if (cmd[0] == "Add Stop")
  17.                 {
  18.                     if (int.Parse(cmd[1]) < input.Length)
  19.                     {
  20.                         int index = int.Parse(cmd[1]);
  21.                         string str = cmd[2];
  22.                         input = input.Insert(index, str);
  23.                     }
  24.  
  25.                     Console.WriteLine(input);
  26.                 }
  27.                 else if (cmd[0] == "Remove Stop")
  28.                 {
  29.                     if (int.Parse(cmd[1]) < input.Length && int.Parse(cmd[2]) < input.Length)
  30.                     {
  31.                         input = input.Remove(int.Parse(cmd[1]), int.Parse(cmd[2]) - int.Parse(cmd[1]) + 1);
  32.                     }
  33.  
  34.                     Console.WriteLine(input);
  35.                 }
  36.                 else if (cmd[0] == "Switch")
  37.                 {
  38.                     if (input.Contains(cmd[1]))
  39.                     {
  40.                         input = input.Replace(cmd[1], cmd[2]);
  41.                     }
  42.  
  43.                     Console.WriteLine(input);
  44.                 }
  45.  
  46.                 command = Console.ReadLine();
  47.             }
  48.  
  49.             Console.WriteLine($"Ready for world tour! Planned stops: {input}");
  50.         }
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement