广发英雄帖,诚征54(52)张扑克牌的洗牌算法
个人觉得就是数组打乱 不知道是否有神马成型的算法
std::random_shuffle
程序代码:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void swap(int* a,int* b)
{
int tmp;
tmp=*a;
*a=*b;
*b=tmp;
}
int main()
{
srand((unsigned)time(NULL));
int poker[52];
int i;
int rnd;
for(i=0;i<52;i++) poker[i]=i+1;
for(i=1;i<52;i++)
{
rnd = rand() % i;
swap(&poker[i],&poker[rnd]);
}
for(i=0;i<52;i++)
{
if(i%6==0 && i>0) printf("\n\n");
printf("%6d",poker[i]);
}
printf("\n");
return 0;
}

