Simulate the dealer's blackjack hand: report blackjack, bust, or the final score after the dealer plays by fixed rules.
Easy3SimulationImplementationInterviewNo attempts yetTime limit8sMemory limit512 MBBlackjack is played with one or more decks of cards. Each player tries to bring the score of the hand as close to 21 as possible without going over 21. The score is the total point value of the cards in the hand. Cards from 2 to 10 are worth their face value, and face cards (jack, queen, king) are worth 10 points. An ace counts as 11 or 1, whichever brings the score closer to 21 without exceeding it. A hand worth more than 21 points is bust, and a player who busts loses at once. A hand of exactly two cards worth 21 points, that is, an ace together with a ten-point card (a face card or a ten), is a blackjack and is treated as a special hand.
The game runs like this. The dealer deals two cards to every player and two cards to himself. If the dealer holds a blackjack, the dealer wins and the round ends immediately. Otherwise every player holding a blackjack wins at once. The remaining players take their turns one by one. On his turn a player either takes another card (hit) or stops taking cards (stand). He may hit repeatedly until he stands or busts, and once his turn is over the next player begins. After every player has finished, the dealer plays by these rules:
Players who do not bust and score higher than the dealer win, and every player who did not bust wins when the dealer busts. Only the dealer matters here, so the results of the players are not computed.
Write a program that reports the score of the dealer's hand after the dealer finishes playing, for each given sequence of cards.
The first line contains a positive integer N, the number of test cases. Then N test cases follow.
Each case consists of two lines. The first line contains two characters, the cards in the dealer's initial hand. The second line contains eight characters, the top eight cards of the pile after all players finish their plays.
A character that represents a card is one of A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, where A is an ace, T a ten, J a jack, Q a queen and K a king. Characters in a line are delimited by a single space.
The same card appears at most four times in one test case. Under that condition the dealer never needs to hit more than eight times while following the rules above.
For each case, print one line: blackjack if the dealer has a blackjack, bust if the dealer busts, and otherwise the score of the dealer's hand.