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