Advertisement
knoteva

Untitled

Jul 28th, 2019
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _01._Problem
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string result = string.Empty;
  12.             string input;
  13.  
  14.             while ((input = Console.ReadLine()) != "End")
  15.             {
  16.                 string command = input.Split(" ")[0];
  17.  
  18.                 if (command == "Add")
  19.                 {
  20.                     string str = input.Split(" ")[1];
  21.                     result += str;
  22.                 }
  23.                 else if (command == "Upgrade")
  24.                 {
  25.                     var ch = input.Split(" ")[1].ToCharArray()[0];
  26.                     result = new string(result.Select(r => r == ch ? (char)(ch + 1) : r).ToArray());
  27.                 }
  28.                 else if (command == "Print")
  29.                 {
  30.                     Console.WriteLine(result);
  31.                 }
  32.                 else if (command == "Index")
  33.                 {
  34.                     var ch = input.Split(" ")[1].ToCharArray()[0];
  35.  
  36.                     var indexes = result.Select((s, i) => new { i, s })
  37.                         .Where(t => t.s == ch)
  38.                         .Select(t => t.i)
  39.                         .ToList();
  40.  
  41.                     if (indexes.Count == 0)
  42.                     {
  43.                         Console.WriteLine("None");
  44.                     }
  45.                     else
  46.                     {
  47.                         Console.WriteLine(string.Join(" ", indexes));
  48.                     }
  49.  
  50.                 }
  51.                 else if (command == "Remove")
  52.                 {
  53.                     string str = input.Split(" ")[1];
  54.                     result = result.Replace(str, "");
  55.                 }
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement