Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace TheFinalQuest
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> realMessage = Console.ReadLine().Split(" ").ToList();
- while (true)
- {
- string[] commands = Console.ReadLine().Split(" ");
- string command = commands[0];
- if (command == "Stop")
- {
- break;
- }
- if (command == "Swap")
- {
- string firstWord = commands[1];
- string secondWord = commands[2];
- if (realMessage.Contains(firstWord) && realMessage.Contains(secondWord))
- {
- int firstWordIndex = realMessage.IndexOf(firstWord);
- int secondWordIndex = realMessage.IndexOf(secondWord);
- realMessage[firstWordIndex] = secondWord;
- realMessage[secondWordIndex] = firstWord;
- }
- }
- if (command == "Put")
- {
- string word = commands[1];
- int index = int.Parse(commands[2]) - 1;
- if (index >= 0 && index <= realMessage.Count)
- {
- realMessage.Insert(index, word);
- }
- }
- if (command == "Sort")
- {
- realMessage.Sort();
- realMessage.Reverse();
- // realMessage = realMessage.OrderByDescending(x => x).ToList();
- }
- if (command == "Replace")
- {
- string firstWord = commands[1];
- string secondWord = commands[2];
- if (realMessage.Contains(secondWord))
- {
- int secondWordIndex = realMessage.IndexOf(secondWord);
- realMessage[secondWordIndex] = firstWord;
- }
- }
- if (command == "Delete")
- {
- int index = int.Parse(commands[1]) + 1;
- if (index >= 0 && index < realMessage.Count)
- {
- realMessage.RemoveAt(index);
- }
- }
- }
- Console.WriteLine(string.Join(" ", realMessage));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement