Advertisement
Guest User

Untitled

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