eolymp
bolt
Try our new interface for solving problems
Məsələlər

A No-Win Situation

A No-Win Situation

Consider a simple variation of the card game Blackjack. In this game, a single player plays against the dealer. The game uses a standard deck of cards, where numbered cards are worth the number of points on the card for the cards numbered \textbf{2} to \textbf{10}, \textbf{10} points for the face cards (King, Queen, and Jack) and either \textbf{1} or \textbf{11} points for the Aces. The dealer deals the first card in the deck to the player, the second to the dealer, the third to the player, and the fourth to the dealer. The player then may continue to draw cards until s/he decides that the total is as close as possible to \textbf{21} and stops voluntarily or until s/he goes over \textbf{21}. If the player goes over \textbf{21}, the player loses. Then the dealer must draw cards until s/he reaches \textbf{17} or more points (with aces counting as \textbf{11} when possible). If the dealer goes over \textbf{21}, the dealer loses. If neither of them goes over \textbf{21}, the winner is the one who comes as close as possible to \textbf{21}. If the player and the dealer have the same total, the player wins. For example, suppose the first cards in the deck are Queen, \textbf{6}, \textbf{4}, \textbf{9}, and \textbf{10}. On the initial deal, the player will receive Queen and \textbf{4} (for a total of \textbf{14}) and the dealer will receive \textbf{6} and \textbf{9} (for a total of \textbf{15}). If the player does not select a card, the dealer will have to draw (because the dealer's total is less than \textbf{17}) and will draw the \textbf{10}, going over, so the player will win. But if the player draws a card (the \textbf{10}), the player's total will be \textbf{24}, so the player will lose. In some situations, it is impossible for the player to win. Consider the case when the cards in the deck are: \textbf{10}, \textbf{3}, \textbf{4}, King, \textbf{3}, \textbf{5}. The player will be dealt the cards \textbf{10} and \textbf{4}. The dealer will have \textbf{3} and King. The table below illustrates what happens for each number of cards the player might draw: \includegraphics{https://static.e-olymp.com/content/64/6478f0b79b2ea2d5fe4bf504e113d8befccafb33.jpg} No matter how many cards the player draws, the player cannot win. In this problem, you will analyze decks to determine if they lead to a situation in which the player cannot win. \InputFile The input to the program will be one or more decks. Each deck will be represented by a string, on its own line. Each deck will consist of at least \textbf{4} cards. where a card is either an integer \textbf{d}, \textbf{2} <= \textbf{d} <= \textbf{9}, epresenting a numbered card, or one of the letters \textbf{A}, \textbf{K}, \textbf{Q}, \textbf{J} or \textbf{T}, representing Ace, King, Queen, Jack, or Ten, respectively. The letters will be in upper case. There will be no other characters on a line. In particular, there will be no spaces. There will always be enough cards to try all valid draws. End of input is indicated by the word 'JOKER', alone on a line. \OutputFile Print a list of responses for the input sets, one per line. Print the word '\textbf{Yes}' if there is a number of cards the player can draw and win, and '\textbf{No}' if there is no way for the player to win. Print these words exactly as they are shown. Do not print any blank lines between outputs.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
Q649T
T34K35
AA2T34A5KKQAJ
JOKER
Çıxış verilənləri #1
Yes
No
Yes