编程介的小学生 2019-08-25 21:21 采纳率: 20.5%
浏览 83

A No-Win Situation用程序代码的实现

Problem Description

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 2 to 10, 10 points for the face cards (King, Queen, and Jack) and either 1 or 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 21 and stops voluntarily or until s/he goes over 21. If the player goes over 21, the player loses. Then the dealer must draw cards until s/he reaches 17 or more points (with aces counting as 11 when possible). If the dealer goes over 21, the dealer loses. If neither of them goes over 21, the winner is the one who comes as close as possible to 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, 6, 4, 9, and 10. On the initial deal, the player will receive Queen and 4 (for a total of 14) and the dealer will receive 6 and 9 (for a total of 15). If the player does not select a card, the dealer will have to draw (because the dealer's total is less than 17) and will draw the 10, going over, so the player will win. But if the player draws a card (the 10), the player's total will be 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: 10, 3, 4, King, 3, 5. The player will be dealt the cards 10 and 4. The dealer will have 3 and King. The table below illustrates what happens for each number of cards the player might draw:

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.

Input
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 4 cards. where a card is either an integer d , 2<=d<=9 ,epresenting a numbered card, or one of the letters A, K, Q, J or 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.

Output
Print a list of responses for the input sets, one per line. Print the word Yes' if there is a number of cards the player can draw and win, andNo' 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.

Sample Input
Q649T
T34K35
AA2T34A5KKQAJ
JOKER

Sample Output
Yes
No
Yes

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog