Advertisement
Briensither

Untitled

Jun 23rd, 2019
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace TheFinalQuest
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> collection = Console.ReadLine().Split(" ").ToList();
  12. string input = " ";
  13. while ((input=Console.ReadLine()) != "Stop")
  14. {
  15. string[] tokens = input.Split().ToArray();
  16. if (tokens[0] == "Delete")
  17. {
  18. int index = int.Parse(tokens[1])+1;
  19. if (index < collection.Count)
  20. {
  21. collection.RemoveAt(index);
  22. }
  23. }
  24. if (tokens[0] == "Swap")
  25. {
  26. string word1 = tokens[1];
  27. string word2 = tokens[2];
  28. if (collection.Contains(word1) && collection.Contains(word2))
  29. {
  30. int indexOf1 = collection.IndexOf(word1);
  31. int indexOf2 = collection.IndexOf(word2);
  32. collection[indexOf1] = word2;
  33. collection[indexOf2] = word1;
  34. }
  35. }
  36. if (tokens[0] == "Put")
  37. {
  38. string word = tokens[1];
  39. int index = int.Parse(tokens[2])-1;
  40. if (index < collection.Count)
  41. {
  42. collection.Insert(index, word);
  43. }
  44. }
  45. if (tokens[0] == "Sort")
  46. {
  47. collection.Sort();
  48. collection.Reverse();
  49. }
  50. if (tokens[0] == "Replace")
  51. {
  52. string word1 = tokens[1];
  53. string word2 = tokens[2];
  54. if (collection.Contains(word2))
  55. {
  56. int index = collection.IndexOf(word2);
  57. collection.RemoveAt(index);
  58. collection.Insert(index, word1);
  59. }
  60. }
  61. }
  62. Console.WriteLine(string.Join(" ",collection));
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement