Card Game
InterviewTime limit1sMemory limit128 MB
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 cards: four of each of the 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
acewhile at least cards remain to be turned over and none of the next cards is a high card, that player scores points. - If a player turns over a
kingwhile at least cards remain to be turned over and none of the next cards is a high card, that player scores points. - If a player turns over a
queenwhile at least cards remain to be turned over and none of the next cards is a high card, that player scores points. - If a player turns over a
jackwhile at least card remains to be turned over and the next card is not a high card, that player scores point.
Input
The input contains 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 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).