C++编程的一道题 100

1.Writeaprogramthatscoresablackjackhand.Inblackjack,aplayerreceivesfromtwoorfivecards... 1. Write a program that scores a blackjack hand. In blackjack, a player receives from two or five cards. The cards 2 through 10 are scored as 2 through 10 points each. The face cards-jack, queen, and king- are scored as 10 points. The goal is to come as close to a score of 21 as possible without going over 21. Hence, any score over 21 is called “busted”. The ace can count as either 1 or 11, whichever is better for the user. For example, an ace and a 10 can be scored as either 11 or 21. Since 21 is a better score, this hand is scored as 21. An ace and two 8s can be scored as either 17 or 27. Since 27 is a “busted” score, this hand is scored as 17.
The user is asked how many cards she or he has, and the user responds with one of the integers 2, 3, 3, or 5. The user is then asked for the card values. Card values are 2 through 10, jack, queen, king, and ace. A good way to handle input is to use the type char so that the card input 2, for example, is read as the character ‘2’, rather than as the number 2. Input the value 2 through 9 as the characters ‘2’ through ‘9’. Input the values 10, jack, queen, king, and ace as the characters ‘t’, ‘j’, ‘q’, ‘k’, and ‘a’. Be sure to allow upper-as well as lowercase letters as input.
After reading in the values, the program should convert them from character values to numeric card sores, taking special care for aces. The output is either a numeric between 2 and 21 or the word “busted”. You program should include a loop that lets the user repeat this calculation until the user says she or he is done.
我用有道翻译的

编写一个程序,打进了21点。在21点,一个球员听命于两个或5张。卡2到10个得分为2到10分。面对,皇后,并cards-jack王-得分为10分。这个目标是为了一样接近21分的情况下将超过21岁。因此,任何得分超过21被称为“破灭了。”酶可以算作一个或11,哪个是更好的为用户。例如,一个空间和10个可以得分为11或21。21世纪是一个从更高的分数,这一方面是得分为21岁。一个空间和两个8是可以拿下17或27岁。27自从“超额”得分,这一方面是得分为17岁。
这个用户是问有多少卡她或他有,并且用户反馈的整数(二)、(三)、(三)、(5)。用户会被要求为卡的价值观。卡值2到10,杰克,国王和王后,王牌。一个好的方法来处理输入使用类型贾泽民以便卡输入2,举例来说,读了“2”,而不是像第二号。输入值2 - 9的人物的2”通过“9”号。输入值10,杰克,国王,王后,作为特征[j]. ' t ',' ',' ',凯西的q,' '。一定要让upper-as作为神经网络输入小写字母一样。
阅读后的价值时,这个程序应该把这些数字卡片从特征值,以特殊的照顾,制胜的法宝。输出或者是一种数字2至21日或单词“破灭了。”你的程序应该包括一个回路,让用户重复这一计算到用户说她或他就完成了。
展开
 我来答
wangbr_bd
2009-12-27
知道答主
回答量:23
采纳率:0%
帮助的人:0
展开全部
新手现编的。
#include<iostream>
#include<string.h>
#include<stdlib.h>

int count[5];//每次发的牌
int temp;//获得牌的次数
int sum;//总分
void score(int i);//计算每次发牌后总分变化
int choose();//依据获得的牌得出获得的分数

char poker[13][10];//(2到ace)十三种牌

void input()
{
strcpy(poker[0],"2");
strcpy(poker[1],"3");
strcpy(poker[2],"4");
strcpy(poker[3],"5");
strcpy(poker[4],"6");
strcpy(poker[5],"7");
strcpy(poker[6],"8");
strcpy(poker[7],"9");
strcpy(poker[8],"10");
strcpy(poker[9],"J");
strcpy(poker[10],"Q");
strcpy(poker[11],"K");
strcpy(poker[12],"ace");
printf("input over");

}

void shuffle()//洗牌
{
printf("now shuffle\n");
int i;
sum=0;
temp=0;
for(i=0;i<5;i++)
count[i]=rand()%13;

printf("shuffle over,sum=%d\n",sum);

}

void receivecard(int i)//发牌
{
printf("\nsum=%d",sum);
printf("\n获得%s一张\n",poker[i]);

score(i);
if(sum<=21)

printf("the score is %d",sum);
else
printf("busted");

}

void score(int i)
{
int a,b;
if (strcmp(poker[i],"ace")==0)
a=choose();
else{

b=poker[i][0];

if(b>57||b<50)

a=10;

else
a=b-48;
}
printf("相当于%d分\n",a);
sum+=a;
}
int choose()
{
if ((sum+11)<=21)
return 11;
else return 1;
}

void main()
{
input();
char answer;

while(1)
{

printf("\nchoose \na,洗牌重来\nb,发牌\nc计算分数\nd,退出\n");
scanf("%c",&answer);
getchar();

switch(answer)

{

case 'a':
printf("a\n");

shuffle();

break;

case 'b':
printf("b\n");
if(temp>4)
printf("\nyou can't get more cards\n");
else
{
//printf("temp=%d\n",temp);
receivecard(count[temp]);

++temp;
printf("\n已经获得%d张牌\n",temp);
}

break;

case 'c':
printf("c\n");
printf("sum=%d",sum);
break;
case 'd':
exit(1);
break;
default:
break;

}
}

}
还有就是这个译文比原文有趣哈。
疾似云流
2009-12-24 · TA获得超过1159个赞
知道小有建树答主
回答量:1093
采纳率:0%
帮助的人:483万
展开全部
0分
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友bb8f36b
2009-12-24 · TA获得超过1402个赞
知道小有建树答主
回答量:970
采纳率:0%
帮助的人:647万
展开全部
一般没中文的题目很少有人做的
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式