Advertisement
Krum_50

World Tour

Jan 12th, 2021
2,239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 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.Insert(firstSimvol, name);
  30.                     }
  31.                     Console.WriteLine(line);
  32.                 }
  33.                 if (simvol == 'R')
  34.                 {
  35.                     int startIndex =int.Parse(tokens[1]);
  36.                     int endIndex = int.Parse(tokens[2]);
  37.                     if ((startIndex >= 0) && (startIndex < endIndex) && (endIndex < line.Length))
  38.                     {
  39.                         line.Remove(startIndex,endIndex-startIndex);
  40.                         Console.WriteLine(line);
  41.                     }
  42.                 }
  43.                 if (simvol == 'S')
  44.                 {
  45.                     string oldString = tokens[1];
  46.                     string newString = tokens[2];
  47.                     line.Replace(oldString, newString);
  48.                     Console.WriteLine(line);
  49.                 }
  50.             }
  51.         }
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement