编程介的小学生 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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧
    • ¥15 #MATLAB仿真#车辆换道路径规划