Under construction

Still being built. Things may change

Card Game

Interview

Time limit1sMemory limit128 MB

Summary
Simulate a 52-card game where players alternate turning cards; award points when a high card is followed by enough non-high cards, then print each score.
Level

Easy3 of 10

Topics
Simulation, Implementation, Array, String
Solved
No attempts yet

Problem

Write a program that keeps score for a simple two-player game played with a deck of cards. The deck has 5252 cards: four of each of the 1313 possible names two, three, four, five, six, seven, eight, nine, ten, jack, queen, king, ace. The cards jack, queen, king, and ace are collectively known as high cards.

The deck is shuffled and placed face-down on the table. Player A turns over the top card and puts it on a pile; then player B turns over the top card and puts it on the pile. A and B keep alternating until the deck is exhausted. Score the game as follows:

  • If a player turns over an ace while at least 44 cards remain to be turned over and none of the next 44 cards is a high card, that player scores 44 points.
  • If a player turns over a king while at least 33 cards remain to be turned over and none of the next 33 cards is a high card, that player scores 33 points.
  • If a player turns over a queen while at least 22 cards remain to be turned over and none of the next 22 cards is a high card, that player scores 22 points.
  • If a player turns over a jack while at least 11 card remains to be turned over and the next card is not a high card, that player scores 11 point.

Input

The input contains 5252 lines. Each line contains the name of one card in the deck, in lowercase letters. The first line is the first card to be turned over, the next line is the next card, and so on.

Output

Whenever a player scores, print Player X scores n point(s)., where X is the player's name (A or B) and nn is the number of points scored (1, 2, 3, or 4). At the end of the game, print each player's total score on two lines:

Player A: n point(s).
Player B: m point(s).

Examples3

  1. Example 1

    Input
    three
    seven
    queen
    eight
    five
    ten
    king
    eight
    jack
    queen
    six
    queen
    jack
    eight
    seven
    three
    ten
    four
    king
    nine
    six
    seven
    ace
    four
    jack
    ace
    ten
    nine
    ten
    queen
    ace
    king
    seven
    two
    five
    two
    five
    nine
    three
    king
    six
    eight
    jack
    six
    five
    four
    two
    ace
    four
    three
    two
    nine
    
    Expected output
    Player A scores 2 point(s).
    Player A scores 1 point(s).
    Player A scores 3 point(s).
    Player B scores 3 point(s).
    Player A scores 1 point(s).
    Player B scores 4 point(s).
    Player A: 7 point(s).
    Player B: 7 point(s).
    
  2. Example 2

    Input
    two
    two
    two
    two
    three
    three
    three
    three
    four
    four
    four
    four
    five
    five
    five
    five
    six
    six
    six
    six
    seven
    seven
    seven
    seven
    eight
    eight
    eight
    eight
    nine
    nine
    nine
    nine
    ten
    ten
    ten
    ten
    jack
    jack
    jack
    jack
    queen
    queen
    queen
    queen
    king
    king
    king
    king
    ace
    ace
    ace
    ace
    
    Expected output
    Player A: 0 point(s).
    Player B: 0 point(s).
    
  3. Example 3

    Input
    ace
    two
    two
    two
    two
    king
    three
    three
    three
    queen
    three
    four
    jack
    four
    ace
    four
    four
    five
    five
    king
    five
    five
    six
    queen
    six
    six
    jack
    six
    ace
    seven
    seven
    seven
    seven
    king
    eight
    eight
    eight
    queen
    eight
    nine
    jack
    nine
    ace
    nine
    nine
    ten
    ten
    king
    ten
    ten
    queen
    jack
    
    Expected output
    Player A scores 4 point(s).
    Player B scores 3 point(s).
    Player B scores 2 point(s).
    Player A scores 1 point(s).
    Player A scores 4 point(s).
    Player B scores 3 point(s).
    Player B scores 2 point(s).
    Player A scores 1 point(s).
    Player A scores 4 point(s).
    Player B scores 3 point(s).
    Player B scores 2 point(s).
    Player A scores 1 point(s).
    Player A scores 4 point(s).
    Player A: 19 point(s).
    Player B: 15 point(s).