Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _01._Problem
- {
- class Program
- {
- static void Main(string[] args)
- {
- string result = string.Empty;
- string input;
- while ((input = Console.ReadLine()) != "End")
- {
- string command = input.Split(" ")[0];
- if (command == "Add")
- {
- string str = input.Split(" ")[1];
- result += str;
- }
- else if (command == "Upgrade")
- {
- var ch = input.Split(" ")[1].ToCharArray()[0];
- result = new string(result.Select(r => r == ch ? (char)(ch + 1) : r).ToArray());
- }
- else if (command == "Print")
- {
- Console.WriteLine(result);
- }
- else if (command == "Index")
- {
- var ch = input.Split(" ")[1].ToCharArray()[0];
- var indexes = result.Select((s, i) => new { i, s })
- .Where(t => t.s == ch)
- .Select(t => t.i)
- .ToList();
- if (indexes.Count == 0)
- {
- Console.WriteLine("None");
- }
- else
- {
- Console.WriteLine(string.Join(" ", indexes));
- }
- }
- else if (command == "Remove")
- {
- string str = input.Split(" ")[1];
- result = result.Replace(str, "");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement