C语言考试题大神求代码啊!!!!用随机数生成器列出所有扑克牌的名字
题目有两个要求:1:应用结构体。2:包含两个函数。第一个是洗牌函数shuffer(),第二个dealing()函数(不太明白题意)原文是:Usingarandomnumb...
题目有两个要求:
1:应用结构体。
2:包含两个函数。第一个是洗牌函数shuffer(),第二个dealing()函数(不太明白题意)
原文是:
Using a random number generation to develop a card shuffling and dealing simulation program.1.using shuffer(),and deal() functions to make it work. 2.using structures
牌的数字:
face: 1-13 or{"Ace","Deuce","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"}牌的种类:
suit: "hearts", "clubs", "spades", "diamonds"
Output 展开
1:应用结构体。
2:包含两个函数。第一个是洗牌函数shuffer(),第二个dealing()函数(不太明白题意)
原文是:
Using a random number generation to develop a card shuffling and dealing simulation program.1.using shuffer(),and deal() functions to make it work. 2.using structures
牌的数字:
face: 1-13 or{"Ace","Deuce","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"}牌的种类:
suit: "hearts", "clubs", "spades", "diamonds"
Output 展开
展开全部
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<stdlib.h>
struct cards{
int suit;
int face;
};
char face[13][10]={" Ace","Deuce","Three"," Four"," Five"," Six","Seven","Eight"," Nine"," Ten"," Jack","Queen"," King"};
char suit[4][10]={"hearts ", "clubs ", "spades ", "diamonds"};
void shuffer(struct cards card[])
{
int i, j, a[52], b[52];
srand((int)time(0));
for(i=0; i<52; i++)
a[i] = i;
for(i=0; i<52; i++)
{
j = rand()%52;
if(a[j]!=-1)
{
b[i] = a[j];
a[j] = -1;
}
else
{
while(a[j]==-1)
j=++j%52;
b[i] = a[j];
}
}
for(i=0; i<52; i++)
{
card[i].face = b[i]%13;
card[i].suit = b[i]/13;
}
}
void deal(struct cards card[])
{
int i, j, k;
k = 1;
for(k=0, i=0; i<13; i++)
{
for(j=0; j<4; j++)
{
// printf("%d %d %d\n", k, card[k].suit, card[k++].face);
printf("%s of %s ", face[card[k].face], suit[card[k++].suit]);
}
printf("\n");
}
}
int main()
{
struct cards card[52];
shuffer(card);
deal(card);
}
#include<string.h>
#include<time.h>
#include<stdlib.h>
struct cards{
int suit;
int face;
};
char face[13][10]={" Ace","Deuce","Three"," Four"," Five"," Six","Seven","Eight"," Nine"," Ten"," Jack","Queen"," King"};
char suit[4][10]={"hearts ", "clubs ", "spades ", "diamonds"};
void shuffer(struct cards card[])
{
int i, j, a[52], b[52];
srand((int)time(0));
for(i=0; i<52; i++)
a[i] = i;
for(i=0; i<52; i++)
{
j = rand()%52;
if(a[j]!=-1)
{
b[i] = a[j];
a[j] = -1;
}
else
{
while(a[j]==-1)
j=++j%52;
b[i] = a[j];
}
}
for(i=0; i<52; i++)
{
card[i].face = b[i]%13;
card[i].suit = b[i]/13;
}
}
void deal(struct cards card[])
{
int i, j, k;
k = 1;
for(k=0, i=0; i<13; i++)
{
for(j=0; j<4; j++)
{
// printf("%d %d %d\n", k, card[k].suit, card[k++].face);
printf("%s of %s ", face[card[k].face], suit[card[k++].suit]);
}
printf("\n");
}
}
int main()
{
struct cards card[52];
shuffer(card);
deal(card);
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询