Facebook
From Rossen Stefanov, 3 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 57
  1. string_cards = input()
  2. list_cards = string_cards.split(':')
  3. deck = []
  4. while True:
  5.     command = input()
  6.     if command == 'Ready':
  7.         break
  8.     command_list = command.split()
  9.     if command_list[0] == 'Add':
  10.         if command_list[1] in list_cards:
  11.             deck.append(command_list[1])
  12.             list_cards.remove(command_list[1])
  13.         else:
  14.             print("Card not found.")
  15.     elif command_list[0] == 'Insert':
  16.         if int(command_list[2]) >= len(deck):
  17.             print('Error!')
  18.         elif command_list[1] in list_cards:
  19.             deck.insert(int(command_list[2]), command_list[1])
  20.         else:
  21.             print('Error!')
  22.     elif command_list[0] == 'Remove':
  23.         if command_list[1] in deck:
  24.             deck.remove(command_list[1])
  25.         else:
  26.             print("Card not found.")
  27.     elif command_list[0] == 'Swap':
  28.         index1 = None
  29.         index2 = None
  30.         for i in range(len(deck)):
  31.             if deck[i] == command_list[1]:
  32.                 index1 = i
  33.             elif deck[i] == command_list[2]:
  34.                 index2 = i
  35.         deck[index1], deck[index2] = deck[index2], deck[index1]
  36.     elif command == 'Shuffle deck':
  37.         deck = deck[::-1]
  38.  
  39. print(*deck)