Advertisement
silvana1303

world tour

Oct 9th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using System.Text;
  6.  
  7.  
  8. namespace Final_Exam
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string input = Console.ReadLine();
  15.  
  16.             string[] command = Console.ReadLine().Split(':');
  17.  
  18.             while (command[0] != "Travel")
  19.             {
  20.                 if (command[0] == "Add Stop")
  21.                 {
  22.                     //•   Add Stop:{index}:{string}
  23.  
  24.                     int index = int.Parse(command[1]);
  25.                     if (index >= 0 && index < input.Length)
  26.                     {
  27.                         input = input.Insert(index, command[2]);
  28.                         //Console.WriteLine(input);
  29.                     }
  30.                 }
  31.                 if (command[0] == "Remove Stop")
  32.                 {
  33.                     //•   Remove Stop:{start_index}:{end_index}
  34.                     int start = int.Parse(command[1]);
  35.                     int end = int.Parse(command[2]);
  36.  
  37.                     if ((start >= 0 && start < input.Length) && end >= 0 && end < input.Length)
  38.                     {
  39.                         input = input.Remove(start, end - start + 1);
  40.                         //Console.WriteLine(input);
  41.                     }
  42.                 }
  43.                 if (command[0] == "Switch")
  44.                 {
  45.                     //•   Switch:{old_string}:{new_string}
  46.                     if (input.Contains(command[1]))
  47.                     {
  48.                         input = input.Replace(command[1], command[2]);
  49.                         //Console.WriteLine(input);
  50.                     }
  51.                 }
  52.  
  53.                 Console.WriteLine(input);
  54.                 command = Console.ReadLine().Split(':');
  55.             }
  56.  
  57.             Console.WriteLine($"Ready for world tour! Planned stops: {input}");
  58.  
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement