CardCount
SRM 161 · 2003-08-28 · by brett1479
SRM 161 · 2003-08-28 · by brett1479 · String Manipulation
Problem Statement
Problem Statement
You are dealing cards to a group of players. In this game, the cards are numbered 0-9 and have no distinguishing
characteristics other than their numbers. A given deck may have many cards that share the same number. You are given an
int numPlayers that represents the number of people playing. You are also given a String
deck which contains the cards to be used (0th character is the top of the deck, and the last character is the bottom).
You will deal the cards starting with player 0, then player 1, until you reach player numPlayers-1, dealing one card
at a time. Then you repeat this process until the cards are exhausted. Cards are always dealt from the top of the deck.
You will return aString[] that shows each of the players' cards in the order they were dealt (cards dealt
earlier show up earlier in the particular String ). Player k's hand corresponds to element k of
the returned String[] . One added constraint is that each player must be dealt the same number of cards. To enforce this
constraint you will not deal extra cards that will unbalance the players' hands (cards held). In other words, if you have
dealt to the last player, and don't have enough cards to deal another to every player, stop dealing. The returned String[] must contain exactly numPlayers elements, each element containing exactly the same number of characters.
You will return a
Constraints
- numPlayers will be between 1 and 50 inclusive
- deck will contain between 0 and 50 characters inclusive, all of which are numeric (0-9)
Examples
0)
6
"012345012345012345"
Returns: { "000", "111", "222", "333", "444", "555" }
Exactly enough to deal 3 to each player.
1)
4
"111122223333"
Returns: { "123", "123", "123", "123" }
2)
1
"012345012345012345"
Returns: { "012345012345012345" }
Only a single player.
3)
6
"01234"
Returns: { "", "", "", "", "", "" }
Not enough cards to deal 1 to each player.
4)
2
""
Returns: { "", "" }
No cards.
Submissions are judged against all 66 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class CardCount with a public method vector<string> dealHands(int numPlayers, string deck) · 66 test cases · 2 s / 256 MB per case