关闭

洗牌!!!随机数序列~!

315人阅读 评论(0) 收藏 举报
分类:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 54

void PokerShuffle(int a[],int n)
{
	int r,i;
	srand(time(NULL));
    for (i=1;i<=n;)
    {
        r = rand()%n;		
        if (a[r] == 0)
			a[r]=i++;
    }
	for(i=0;i<n;i++)
		a[i]-=1;
}

int main(void)
{
	char c,j,a[][7]={"大鬼  ","小鬼  ",
		"红桃A ","红桃K ","红桃Q ","红桃J ","红桃10","红桃9 ",
        "红桃8 ","红桃7 ","红桃6 ","红桃5 ","红桃4 ","红桃3 ","红桃2 ",
		"黑桃A ","黑桃K ","黑桃Q ","黑桃J ","黑桃10","黑桃9 ",
        "黑桃8 ","黑桃7 ","黑桃6 ","黑桃5 ","黑桃4 ","黑桃3 ","黑桃2 ",
		"方块A ","方块K ","方块Q ","方块J ","方块10","方块9 ",
        "方块8 ","方块7 ","方块6 ","方块5 ","方块4 ","方块3 ","方块2 ",
		"草花A ","草花K ","草花Q ","草花J ","草花10","草花9 ",
        "草花8 ","草花7 ","草花6 ","草花5 ","草花4 ","草花3 ","草花2 "};
	
    int b[N] = {0} ;
    
	PokerShuffle(b,N);

	for(j=0;j<N;j++)
		printf("%s ",a[b[j]]);
	printf("\n");

    return 0;
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:20997次
    • 积分:635
    • 等级:
    • 排名:千里之外
    • 原创:44篇
    • 转载:2篇
    • 译文:0篇
    • 评论:5条
    最新评论