Advertisement
Guest User

Untitled

a guest
Jan 12th, 2021
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace World_Tour
  6. {
  7.     class Program
  8.     {
  9.         public static int firstSymvol { get; private set; }
  10.         static void Main(string[] args)
  11.         {
  12.             string line = Console.ReadLine();
  13.             while (true)
  14.             {
  15.                 string command = Console.ReadLine();
  16.                 if(command=="Travel")
  17.                 {
  18.                     Console.WriteLine($"Ready for world tour! Planned stops: {line}");
  19.                     return;
  20.                 }
  21.                 string[] tokens = command.Split(":").ToArray();
  22.                 char simvol = tokens[0][0];
  23.                 if(simvol=='A')
  24.                 {
  25.                     int firstSimvol =int.Parse(tokens[1]);
  26.                     string name = tokens[2];
  27.                     if ((firstSymvol >= 0) && (firstSymvol < line.Length))
  28.                     {
  29.                         line = line.Insert(firstSimvol, name);
  30.                     }
  31.                 }
  32.                 if (simvol == 'R')
  33.                 {
  34.                     int startIndex =int.Parse(tokens[1]);
  35.                     int endIndex = int.Parse(tokens[2]);
  36.                     if ((startIndex >= 0) && (startIndex < line.Length) && (endIndex >= 0) && (endIndex < line.Length))
  37.                     {
  38.                         line = line.Remove(startIndex,endIndex-startIndex + 1);
  39.                     }
  40.                 }
  41.                 if (simvol == 'S')
  42.                 {
  43.                     string oldString = tokens[1];
  44.                     string newString = tokens[2];
  45.                     line = line.Replace(oldString, newString);
  46.                    
  47.                 }
  48.               Console.WriteLine(line);
  49.             }
  50.         }
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement