发牌原程序见我的空间(http://hi.baidu.com/crazycola/blog/item/52402bd4b3f68705a08bb746.html),可选是否包含大小王,可选发牌列数。
以下为改过的版本,不包含大小王(即总数52张),只能发4堆。
另外附加了用户菜单,原程序中不含菜单部分。
代码如下:
---------------------------------------
#include
#include
#include
int menu()
{
int choice;
printf("1 发牌/0 退出:");
scanf("%d",&choice);
return choice;
}
void main( void )
{
int i1, j, total;
int *iArr;
int tag = 0;
char* pok_C[] = { "黑桃", "红桃", "梅花", "方块" };
char* pok_N[] = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
if(!menu()) exit(0);
total = 52;
srand( (unsigned)time( NULL ) );
iArr = (int*)malloc(total*sizeof(int));
for( i1=0; i1
{
iArr[i1]=rand()%total;
if( i1==0 ) continue;
do {
tag = 0;
for( j=0; j
if( iArr[j] == iArr[i1] )
{
iArr[i1]=rand()%total;
tag = 1;
}
} while( tag==1 );
}
for( i1=0; i1
{
printf("%s%s\t",pok_C[iArr[i1]%4],pok_N[iArr[i1]%13]);
if(i1%4==3) printf("\n");
}
free(iArr);
}
温馨提示:答案为网友推荐,仅供参考