Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Problem3
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> cards = Console.ReadLine()
- .Split(":", StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- List<string> deck = new List<string>();
- while (true)
- {
- string line = Console.ReadLine();
- if (line == "Ready")
- {
- break;
- }
- string[] tokens = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
- string command = tokens[0];
- if (command == "Add")
- {
- string cardName = tokens[1];
- if (Exist(cards, cardName))
- {
- deck.Add(cardName);
- }
- else
- {
- Console.WriteLine("Card not found.");
- }
- }
- else if (command == "Insert")
- {
- string cardName = tokens[1];
- int index = int.Parse(tokens[2]);
- if (Exist(cards, cardName) &&
- IsValidIndex(cards, index))
- {
- deck.Insert(index, cardName);
- }
- else
- {
- Console.WriteLine("Error!");
- }
- }
- else if (command == "Remove")
- {
- string cardName = tokens[1];
- if (Exist(deck, cardName))
- {
- deck.Remove(cardName);
- }
- else
- {
- Console.WriteLine("Card not found.");
- }
- }
- else if (command == "Swap")
- {
- string cardName1 = tokens[1];
- string cardName2 = tokens[2];
- int indexCard1 = deck.IndexOf(cardName1);
- int indexCard2 = deck.IndexOf(cardName2);
- string oldElement = deck[indexCard1];
- deck[indexCard1] = deck[indexCard2];
- deck[indexCard2] = oldElement;
- }
- else if (command == "Shuffle")
- {
- deck.Reverse();
- }
- }
- Console.WriteLine(string.Join(' ',deck));
- }
- private static bool IsValidIndex(List<string> cards, int index)
- {
- return index >= 0 && index < cards.Count;
- }
- private static bool Exist(List<string> cards, string card)
- {
- return cards.Contains(card);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement