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> collection = Console.ReadLine().Split(" ").ToList();
- string input = " ";
- while ((input=Console.ReadLine()) != "Stop")
- {
- string[] tokens = input.Split().ToArray();
- if (tokens[0] == "Delete")
- {
- int index = int.Parse(tokens[1])+1;
- if (index < collection.Count)
- {
- collection.RemoveAt(index);
- }
- }
- if (tokens[0] == "Swap")
- {
- string word1 = tokens[1];
- string word2 = tokens[2];
- if (collection.Contains(word1) && collection.Contains(word2))
- {
- int indexOf1 = collection.IndexOf(word1);
- int indexOf2 = collection.IndexOf(word2);
- collection[indexOf1] = word2;
- collection[indexOf2] = word1;
- }
- }
- if (tokens[0] == "Put")
- {
- string word = tokens[1];
- int index = int.Parse(tokens[2])-1;
- if (index < collection.Count)
- {
- collection.Insert(index, word);
- }
- }
- if (tokens[0] == "Sort")
- {
- collection.Sort();
- collection.Reverse();
- }
- if (tokens[0] == "Replace")
- {
- string word1 = tokens[1];
- string word2 = tokens[2];
- if (collection.Contains(word2))
- {
- int index = collection.IndexOf(word2);
- collection.RemoveAt(index);
- collection.Insert(index, word1);
- }
- }
- }
- Console.WriteLine(string.Join(" ",collection));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement