Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Text.RegularExpressions;
- namespace _6
- {
- class Program
- {
- static void Main(string[] args)
- {
- string countries = Console.ReadLine();
- while (true)
- {
- string line = Console.ReadLine();
- if (line == "Travel")
- {
- Console.WriteLine($"Ready for world tour! Planned stops: {countries}");
- break;
- }
- string[] tokens = line.Split(":");
- switch (tokens[0])
- {
- case "Switch":
- {
- string stringToCheck = tokens[1];
- string stringToAdd = tokens[2];
- bool checkIfItContainsChar = countries.Contains(stringToCheck);
- if (checkIfItContainsChar == true)
- {
- string replacement = countries.Replace(stringToCheck, stringToAdd);
- countries = replacement;
- Console.WriteLine(countries);
- }
- else
- {
- }
- break;
- }
- case "Add Stop":
- {
- int stringToAddIndex = int.Parse(tokens[1]);
- string stringToAdd = tokens[2];
- if (stringToAddIndex <= countries.Length && stringToAddIndex >= 0)
- {
- string CutString = countries.Insert(stringToAddIndex, stringToAdd);
- countries = CutString;
- Console.WriteLine(countries);
- }
- break;
- }
- case "Remove Stop":
- {
- int stringToCutFirstIndex = int.Parse(tokens[1]);
- int stringToCutSecondIndex = int.Parse(tokens[2]);
- if (stringToCutFirstIndex <= countries.Length && stringToCutSecondIndex <= countries.Length && stringToCutSecondIndex >= 0 && stringToCutFirstIndex >= 0)
- {
- string CutString = countries.Remove(stringToCutFirstIndex, stringToCutSecondIndex - stringToCutFirstIndex + 1);
- countries = CutString;
- Console.WriteLine(countries);
- }
- else
- {
- }
- break;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement