Connection Status:
Competition Arena > LambChop
SRM 142 · 2003-04-15 · by TangentZ
Class Name: LambChop
Return Type: int[]
Method Name: scoring
Arg Types: (vector<string>, int)
Problem Statement

Problem Statement

Lamb Chop is a fun party game played with one or more decks of ordinary playing cards.

The cards are denoted 'A','2','3','4','5','6','7','8','9','T','J','Q','K'. 'A' is Ace with a value of 1. 'T' is Ten with a value of 0. 'J' is Jack with a value of 1. 'Q' is Queen with a value of 2. 'K' is King with a value of 3. All other cards have their face values. Suits do not matter.

The players are arranged in a circle with a table in the center. Label the players as Player 0, Player 1, Player 2... etc, in the clockwise direction. The cards are shuffled into one deck and put on the table facing down.

All players start with a score of 0. The group also keeps a counter, starting at 1. Player 0 starts the game.

The game of Lamb Chop proceeds as follows:

  • 1. Everyone shouts out the counter and the current player flips the top card over for all to see.
  • 2. Compare the value of the card with the rightmost digit of the counter:
    • a. They are equal. The current player is considered a lamb and is out of the current round (put on the chopping board). The counter is reset to 1.
    • b. They are not equal. The counter is incremented by 1.
  • 3. Check for the following events (in this order):
    • a. There are no more cards left in the deck. Each non-lamb player gets 1 point. Go to Step 5.
    • b. There is only one non-lamb player left. That player gets points equal to the number of players. Go to Step 5.
  • 4. The next non-lamb player in the clockwise direction gets the turn to flip a card. Go to Step 1.
  • 5. Reshuffle the cards. Players keep their previous positions and are no longer considered lambs. The counter is reset to 1. The player who last flipped a card gets the turn to flip a card again. Go to Step 1.

You are given a String[], cards, each of whose elements represents a round of the Lamb Chop game, in the order that the rounds occur. Each element represents the deck of cards used in that round, from top to bottom (i.e., character 0 is the top card). Your task is to write a function that returns the scores of the players as a int[] after the last round is played. Element 0 is the score of Player 0. Element 1 is the score of Player 1 and so on. There should be exactly numPlayers number of elements.

Notes

  • Player 0 always starts the Lamb Chop game at the beginning of the first round
  • There may be more than 4 of each card in the shuffled deck since more than one normal deck may be used
  • Each round may use a different number of cards

Constraints

  • cards contains between 0 and 50 elements, inclusive
  • Each element of cards contains between 1 and 50 characters, inclusive
  • Each element of cards contains only the characters 'A','2','3','4','5','6','7','8','9','T','J','Q','K'
  • numPlayers is between 2 and 10, inclusive
Examples
0)
{"T694A","Q2345"}
2
Returns: { 2,  2 }

1. Player 0 flips the 'T' card, counter is 1. Continue. 2. Player 1 flips the '6' card, counter is 2. Continue. 3. Player 0 flips the '9' card, counter is 3. Continue. 4. Player 1 flips the '4' card, counter is 4. Player 1 becomes a lamb! 5. Only Player 0 is left. Player 0 gets 2 points. Scores are {2,0} 6. New round starts with next deck. 7. Player 1 flips the 'Q' card, counter is 1. Continue. 8. Player 0 flips the '2' card, counter is 2. Player 0 becomes a lamb! 9. Only Player 1 is left. Player 1 gets 2 points. Scores are {2,2} 10. There are no more decks left. The game ends. Return {2,2}

1)
{"T6945983QK","Q7384535TJ"}
3
Returns: { 3,  1,  1 }

1. Player 0 flips 'T', counter is 1. 2. Player 1 flips '6', counter is 2. 3. Player 2 flips '9', counter is 3. 4. Player 0 flips '4', counter is 4. Lamb! 5. Player 1 flips '5', counter is 1. 6. Player 2 flips '9', counter is 2. 7. Player 1 flips '8', counter is 3. 8. Player 2 flips '3', counter is 4. 9. Player 1 flips 'Q', counter is 5. 10. Player 2 flips 'K', counter is 6. 11. Out of cards. Player 1 and Player 2 get 1 point. Scores are {0,1,1} 12. New round, new deck 13. Player 2 flips 'Q', counter is 1. 14. Player 0 flips '7', counter is 2. 15. Player 1 flips '3', counter is 3. Lamb! 16. Player 2 flips '8', counter is 1. 17. Player 0 flips '4', counter is 2. 18. Player 2 flips '5', counter is 3. 19. Player 0 flips '3', counter is 4. 20. Player 2 flips '5', counter is 5. Lamb! 21. Only Player 0 is left. Player 0 gets 3 points. Scores are {3,1,1} 22. No new deck. Game Over. Return {3,1,1}.

2)
{"KJQT9867543A2"}
4
Returns: { 1,  1,  1,  1 }

All the cards are flipped but their values never match the rightmost digit of the counter. Everyone gets 1 point.

3)
{"459928TJQ2K78396553A6",
 "9234AT3JKQ",
 "3322455AA88KK57"}
4
Returns: { 2,  5,  2,  1 }
4)
{"98764","T232"}
3
Returns: { 2,  1,  1 }

If every card for the round has been used and there is only one non-lamb player left, that player only gets 1 point.

Submissions are judged against all 71 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class LambChop with a public method vector<int> scoring(vector<string> cards, int numPlayers) · 71 test cases · 2 s / 256 MB per case

Submitting as anonymous