Card Trick

View as PDF

Submit solution

Points: 10
Time limit: 5.0s
Memory limit: 512M

Author:
Problem type
Allowed languages
C, C#, C++, Go, Haskell, Java, JS, Pascal, Perl, Python, Rust

problem header

Gerald and Leanne are doing a card trick. This trick is centred around Gerald guessing the final card in Leanne's hand.

Leanne will begin by drawing 5 random cards from a standard deck of 52 cards. Then, one by one, she will reveal 4 out of the 5 cards she has drawn. After this, without looking, Gerald will respond with the final card that Leanne drew!

Your job is to execute this card trick.

Interaction

This program will be tested across two processes, which will communicate with one another.

Your program should first read in a single integer on a line. If this integer is 0, you are Leanne. If this integer is 1, you are Gerald.

In either case, you should read a single integer T, the number of test cases.

If you are Leanne, T lines will follow, each containing 5 space-separated card values. Card values are represented as 2 characters, the first representing suit (One of SCDH) and the second representing face value (One of A23456789TJQK).

Next, for each test case Leanne should output 4 space-separated card values, that she wants to show Gerald, one by one.

If you are Bob, T lines will follow, each containing 4 space-separated card values, these will be exactly the card values that Leanne printed, in order.

Gerald should then output a single card value for each test case: The value of Leanne's final card.

Constraints
  • 1 \leq T \leq 10^5
  • The five space-separated cards Leanne receives will be distinct.
Example Run

Here is one possible way these two test cases can go:

Leanne's Input:

0
2
ST D5 HJ DA C8
HA SA CA DA H5

Leanne's Output:

D5 DA HJ ST
DA SA CA HA

Gerald's Input:

1
2
D5 DA HJ ST
DA SA CA HA

Gerald's Output:

C8
H5

Comments


  • 1
    admin  commented on Oct. 1, 2022, 1:41 p.m.

    Apologies for missing these comments earlier. The sample input is missing the first 0/1 Thank you for pointing this out.

    @Calloc to answer your question, the tester will run your program twice. The first time, it will run the program with Leanne's input:

    0
    2
    ST D5 HJ DA C8
    HA SA CA DA H5

    Then, the output from Leanne's input is used to generate the input for Gerald's input; a second program:

    1
    2
    D5 DA HJ ST
    DA SA CA HA

    If Gerald then outputs the 2 cards that are omitted from Leanne's output (in the correct order), then your program recieves AC.


  • 0
    Calloc  commented on Oct. 1, 2022, 1:37 p.m.

    What do you mean by "two processes, which will communicate with one another." and how?


  • 0
    Reply2019  commented on Oct. 1, 2022, 12:44 p.m.

    Where is "Your program should first read in a single integer on a line. If this integer is 0, you are Leanne. If this integer is 1, you are Gerald." in the sample input? Thanks.