哪位好心的大哥或大姐可以帮我用C语言编写一下这道题吗?谢谢啦~!

Contents:Thisassignmentgivesstudentstheopportunitytoworkwitharraysandsorting.Programs... Contents: This assignment gives students the opportunity to work with arrays and sorting.Programs that simulate card games usually have to simulate the operation of shuffling the deck. Like sorting, shuffling is a process that involves rearranging the elements of an array. Algorithmically, the only difference between sorting and shuffling is how you select elements. When you sort an array using selection sort, you choose the smallest element in the rest of the array on each cycle of the loop. When you shuffle an array, you choose a random element. At last, you should sort the 13 cards in descending order by suit.
Steps: Write a function Shuffle that shuffles an array of strings. To test the Shuffle function, write a program that.
1. Declares an array with 52 elements, each of which are strings.
2. Fills the elements of that array with strings representing standard playing cards. Each card is represented by a string consisting of a rank (A, K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3, 2) concatenated with a single letter representing a suit (C, D, H, S). Thus, the queen of spades is represented by the string "QS". The function IntegerToString described in Chapter 9 (page 302) will probably come in handy here.
3. Shuffles the array using the Shuffle function.
4. Deals a bridge hand by copying the first 13 cards from the deck to a separate array.
展开
 我来答
鬼火狼烟
2005-12-09 · TA获得超过6333个赞
知道大有可为答主
回答量:2275
采纳率:50%
帮助的人:2741万
展开全部
下面实现给你参考,显示前13张牌

#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#define MAXP 52
#define MAXT 14
#define MAXF 4
#define MAXD 13

typedef struct _p
{
int p1;
int p2;
}PT,*P;

void init(P p[MAXP])
{
int i;
for(i=0;i<MAXP;i++)
{
p[i]->p1 = i % MAXT;
p[i]->p2 = i % MAXF;
}
}
void shuffle(P p[MAXP])
{
int i,k;
PT t[MAXP];
time_t ti;
srand((unsigned) time(&ti));
for(i=0;i<MAXP;i++)t[i].p1=-1;
for(i=0;i<MAXP;i++)
{
k=(int)(((double) rand()/((double) RAND_MAX+1))*(52));
if(-1==t[k].p1)
{
t[k]=*(p[i]);
}
else
{
while(-1!=t[k].p1)
{
(k==(MAXP-1))?k=0:k++;
}
t[k]=*(p[i]);
}
}
for(i=0;i<MAXP;i++)*(p[i])=t[i];
}

void display(P p[MAXP])
{
char* A[14]={"A","1","2","3","4","5","6","7","8","9","10","J","Q","K"};
char* B[4]={"C","D","H","S"};
int k;
for(k=0;k<MAXD;k++)
{
printf("%s%s ",A[p[k]->p1],B[p[k]->p2]);
}
printf("\n");
}

int main(char* a,char** b)
{
int k;
P p[MAXP];
for(k=0;k<MAXP;k++)
{
p[k]=(P)malloc(8);
}
init(p);
shuffle(p);
display(p);
for(k=0;k<MAXP;k++)
{
free(p[k]);
}
return 0;
}
百度网友1b45ae27e
2005-12-09 · TA获得超过303个赞
知道答主
回答量:190
采纳率:100%
帮助的人:0
展开全部
英文的呀!看不懂
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式