标题:Programming practice:Analog CARDS shuffle
取消只看楼主
youbin2014
Rank: 1
等 级:新手上路
帖 子:45
专家分:6
注 册:2015-5-5
结帖率:100%
 问题点数:0 回复次数:0 
Programming practice:Analog CARDS shuffle
/*****************************************************************************************
Programming practice:Analog CARDS shuffle
******************************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

struct cards{
    char *suit[100];
    char *face[100];
};
typedef struct cards CARDS;

void xipai(CARDS *wCards);
void fapai(CARDS *wCards);
void FillCard(CARDS wCard[],char *wFace[],char *wSuit[]);

int main(void)
{
    char *suit[] = {"heitao","hongxing","meihua","fangpain"};
    char *face[] = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
    CARDS card[52];
    srand(time(NULL));
    FillCard(card,face,suit);
    xipai(card);
    fapai(card);
    printf("\n");

    return 0;
}

void FillCard(CARDS wCard[],char *wFace[],char *wSuit[])
{
    int i;
    for(i = 0;i < 52;i++)
    {
        strcpy(wCard[i].face,wFace[i % 13]);
        strcpy(wCard[i].suit,wSuit[i / 13]);
    }
}

void xipai(CARDS *wCards)
{
    int i,j;
    CARDS temp;
    for(i = 0;i < 52;i++)
    {
        j = rand() % 52;
        temp = wCards[i];
        wCards[i] = wCards[j];
        wCards[j] = temp;
    }
}

void fapai(CARDS *wCards)
{
    int i;
    for(i = 0;i < 52;i++)
    {
        printf("%10s%10s",wCards[i].suit,wCards[i].face);
        if(i == 4)
            printf("\n");
    }
}
搜索更多相关主题的帖子: practice shuffle include 
2016-10-31 20:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-470530-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.916159 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved