Advertisement
Denyy111

03. Wizard Poker

Dec 9th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Exam_03
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> myList = Console.ReadLine()
  12. .Split(":")
  13. .ToList();
  14.  
  15. List<string> newList = new List<string>();
  16.  
  17. string input = Console.ReadLine();
  18.  
  19. while (input != "Ready")
  20. {
  21. string[] actions = input.Split(" ");
  22. string command = actions[0];
  23.  
  24. if (command == "Add")
  25. {
  26. string nameCard = actions[1];
  27.  
  28. if (myList.Contains(nameCard))
  29. {
  30. newList.Add(nameCard);
  31. }
  32. else
  33. {
  34. Console.WriteLine("Card not found.");
  35. }
  36. }
  37. else if (command == "Insert")
  38. {
  39. string name = actions[1];
  40. int index = int.Parse(actions[2]);
  41.  
  42. if (index >= 0 && index < myList.Count)
  43. {
  44. if (myList.Contains(name))
  45. {
  46. newList.Insert(index, name);
  47. }
  48. else
  49. {
  50. Console.WriteLine("Error!");
  51. }
  52. }
  53. else
  54. {
  55. Console.WriteLine("Error!");
  56. }
  57. }
  58. else if (command == "Remove")
  59. {
  60. string cardName = actions[1];
  61.  
  62. if (newList.Contains(cardName))
  63. {
  64. newList.Remove(cardName);
  65. }
  66. else
  67. {
  68. Console.WriteLine("Card not found.");
  69. }
  70. }
  71. else if (command == "Swap")
  72. {
  73. string firstWord = actions[1];
  74. string secondWord = actions[2];
  75.  
  76. if (newList.Contains(firstWord) && secondWord.Contains(secondWord)) // dali syshestvuwat dumite
  77. {
  78. int firstWordInex = newList.IndexOf(firstWord);
  79. int secondtWordInex = newList.IndexOf(secondWord); // namirame na koi index sa dumite
  80.  
  81. newList[firstWordInex] = secondWord;
  82. newList[secondtWordInex] = firstWord;
  83. }
  84. }
  85. else if (command == "Shuffle")
  86. {
  87. if (actions[1] == "deck")
  88. {
  89. newList.Reverse();
  90. }
  91.  
  92. }
  93.  
  94. input = Console.ReadLine();
  95. }
  96.  
  97. Console.WriteLine(string.Join(" ", newList));
  98. }
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement