13300 - DS_2021_HW1_LinkedList   

Description

In this homework, we need to implement a draw card game.

  1. N people are playing card game, each of them has M cards.
    • That is, player 1, 2, 3, ... , N.
    • and card 1, 2, 3, ... , M of each player.
  2. We know that there exist K < N joker cards in the deck.
    • Initially, any one of them has at most one joker card in hand.
    • If a player starts off with a Joker in his or her hand, it will be replaced as the first card.
    • That is, if Player A has Joker in the beginning, A’s hand will be Joker, 2, 3, ... , M
    • Otherwise, card 1, 2, 3, ... , M.
  3. Each player draws the next player’s hand in order.
    • That is, player 1 draws player 2’s card.
    • Player 2 draws player 3’s card.
    • Player N draws player 1’s card.​
  4. In each round, we will have two input numbers .
    • Player A draws the ith card from B’s hand, and places it as the jth card.
    • If player B has only t < i cards, then A draws the last card.
    • If player A has only t < j cards, then A places it as the last card.
    • If  i == -1 and j == -1, then stop the game.
  5. Among all the players who does not have Joker in their hands, print the cards (in ascending order) of the player with the smallest index.
    • If this player has no card, then print "\n".
    • Every card is followed by a blank character and a newline character in the end of card.

Input

There are 3 numbers in first line, denoted as N, M, K, respectively.

The next line has K numbers, denoting the index of person who has joker in the beginning.

In the remaining lines, players draw the next player’s hand in order.

  • 2 ≤ N ≤ 100
  • 1 ≤ M ≤ 1,000
  • 1 ≤ K ≤ N-1
  • 1 ≤ Remaining lines ≤ 1,000,000

Output

Among all the players who does not have Joker in their hands, print the cards (in ascending order) of the player with the smallest index.

  • If player has no card, then print "\n".
  • Every card is followed by a blank character and a newline character in the end of card.

Sample Input  Download

Sample Output  Download

Tags




Discuss