Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2021
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace _01._World_Tour
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string input = Console.ReadLine();
  11.             StringBuilder sb = new StringBuilder();
  12.             sb.Append(input);
  13.  
  14.             string cmd = Console.ReadLine();
  15.  
  16.             while (cmd != "Travel")
  17.             {
  18.                 string[] command = cmd.Split(':', StringSplitOptions.RemoveEmptyEntries);
  19.  
  20.                 if (command[0] == "Add Stop")
  21.                 {
  22.                     int index = int.Parse(command[1]);
  23.                     string place = command[2];
  24.                     if (index >= 0 && index < sb.Length)
  25.                     {
  26.                         sb.Insert(index, place);
  27.                     }
  28.  
  29.                     Console.WriteLine(sb);
  30.                 }
  31.  
  32.                 else if (command[0] == "Remove Stop")
  33.                 {
  34.                     int startIndex = int.Parse(command[1]);
  35.                     int endIndex = int.Parse(command[2]);
  36.  
  37.                     if ((startIndex >= 0 && startIndex < sb.Length) && (endIndex < sb.Length && endIndex >= 0) && (startIndex <= endIndex))
  38.                     {
  39.                         sb.Remove(startIndex, (endIndex + 1) - startIndex);
  40.                     }
  41.  
  42.                     Console.WriteLine(sb);
  43.                 }
  44.  
  45.                 else if (command[0] == "Switch")
  46.                 {
  47.                     string oldString = command[1];
  48.                     string newString = command[2];
  49.                     if (sb.ToString().Contains(oldString) && oldString != newString)
  50.                     {
  51.                         sb.Replace(oldString, newString);
  52.                     }
  53.  
  54.                     Console.WriteLine(sb);
  55.                 }
  56.  
  57.                 cmd = Console.ReadLine();
  58.             }
  59.  
  60.             Console.WriteLine($"Ready for world tour! Planned stops: {sb}");
  61.         }
  62.     }
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement