| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 895 人关注过本帖
标题: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
快速回复:Programming practice:Analog CARDS shuffle
数据加载中...
 
   



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

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