做课设出现的问题。关于 EXE 停止工作
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define radix 13
typedef struct
{
int value;
int suit;
char numb;
char huase;
int num;
int order;
int key[2];
int next;
}apoker;
apoker poker[52];
typedef int temp[radix];
apoker *manmakepoker(apoker unsortpoker[], int t)
{
int i,n;
int suit;
char numb;
printf("请输入扑克牌花色和面值pS:3为红桃,4为方块,5为梅花,6为黑桃:\n");
for (i = 0; i < 2*t; i++)//用户输入扑克牌,ASC值
{ n=i%13;//同一个位置的扑克牌
scanf("%d%c", &suit, &numb);
poker[i].huase=suit;
poker[i].value=numb;
poker[i].num=i;
poker[i].order=n;
}
printf("输入的扑克为");//(结构体赋值)
for (i = 0; i<=2*t; i++)
{
n = rand() % 51;
unsortpoker[i].huase = poker[i].huase;
unsortpoker[i].value = poker[i].value;
unsortpoker[i].num = poker[i].num;
unsortpoker[i].order = poker[i].order;
unsortpoker[i].key[0] = unsortpoker[i].huase;
unsortpoker[i].key[1] = unsortpoker[i].order;
printf("%c%c", poker[i].huase, poker[i].value);
}
return unsortpoker;
}
apoker *createpoker(apoker unsortpoker[], int t)//(生成扑克)
{
int i, j, k, m;
int n;
for(i=0;i<52;i++)/*建立整副扑克*/
{ j=i/13;/*将扑克分为四种花色*/
k=(i+2)%13; /*控制面值的输出形式*/
m=i%13;/*同一花色中所处的位置*/
poker[i].order=m;
if(j==0) poker[i].huase=3;/*花色赋值*/
else if(j==1) poker[i].huase=4;
else if(j==2) poker[i].huase=5;
else poker[i].huase=6;
if(k==0) poker[i].value=75;/*面值赋值*/
else if(k==1) poker[i].value=65;
else if(k==11) poker[i].value=74;
else if(k==12) poker[i].value=81;
else poker[i].value=k;
poker[i].num=i;
}
printf("随机生成的扑克:\n");
for(i=1;i<=t;i++)/*生成t张扑克*/
{
n=rand()%51; /*随机生成52以内的数*/
unsortpoker[i].huase=poker[n].huase;/*结构体赋值*/
unsortpoker[i].value=poker[n].value;
unsortpoker[i].num=poker[n].num;
unsortpoker[i].order=poker[n].order;
unsortpoker[i].key[0]=unsortpoker[i].huase; /*关键字赋值*/
unsortpoker[i].key[1]=unsortpoker[i].order;
k=(n+2)%13; /*用num控制value输出形式*/
if(k==0||k==1||k==11||k==12)
printf ("%c%c ",poker[n].huase,poker[n].value);
else printf ("%c%d ",poker[n].huase,poker[n].value);
}
return unsortpoker;
}
void distribute(apoker r[],int i,temp head,temp tail)
{ int j,p;
for(j=0;j<radix;j++)
{head[j]=0;tail[j]=0;} /*将个队列初始化为空队列*/
p=r[0].next; /*p指向链表中的第一个记录*/
while(p!=0)
{
j=r[p].key[i];/*用记录中第i位关键字求相应队列号*/
if(head[j]==0)
head[j]=p;/*将p所指向的结点加入第i个结点中*/
else r[tail[j]].next=p;
tail[j]=p;
p=r[p].next;
}
}
void collect(apoker r[],temp head,temp tail)
{
int j;
int t;
j=0;
while(head[j]==0)/*找第一个非空队列*/
j++;
r[0].next=head[j];
t=tail[j];
while(j<radix-1)/*寻找并串接所有非空队列*/
{
j++;
while((j<radix-1)&&(head[j]==0))/*找下一个非空队列*/
j++;
if(head[j]!=0)/*链接非空队列*/
{
r[t].next=head[j];
t=tail[j];
}
}
r[t].next=0;/*t指向最后一个非空队列中的最后一个结点*/
}
void valuepresort(apoker r[],int len)
{
int i,n,k;
n=len;
temp head,tail;
n=len;
for(i=0;i<=n-1;i++)
r[i].next=i+1;/*构造静态链表*/
r[n].next=0;
for(i=0;i<=1;i++)/*从最低位关键字开始,进行分配收集*/
{
distribute(r,i,head,tail);
collect(r,head,tail);
}
printf("按面值优先排序后的扑克:\n");
for(i=r[0].next;i!=0;i=r[i].next)
{ k=(r[i].num+2)%13; /*用num控制value输出形式*/
if(k==0||k==1||k==11||k==12)
printf ("%c%c ",r[i].huase,r[i].value);
else printf ("%c%d ",r[i].huase,r[i].value);
}
}
void huasepresort(apoker r[],int len)
{
int i,n,k;
n=len;
temp head,tail;
n=len;
for(i=0;i<=n-1;i++)
r[i].next=i+1; /*构造静态链表*/
r[n].next=0;
for(i=1;i>=0;i--) /*从最低位关键字开始,进行分配收集*/
{
distribute(r,i,head,tail);
collect(r,head,tail);
}
printf("按花色排序后的扑克:\n");
for(i=r[0].next;i!=0;i=r[i].next)
{ k=(r[i].num+2)%13; /*用num控制value输出形式*/
if(k==0||k==1||k==11||k==12) printf ("%c%c ",r[i].huase,r[i].value);
else printf ("%c%d ",r[i].huase,r[i].value);
}
}
void main()
{
int i, N;
char ch;
char cha;
apoker unsortpoker[100];
printf("说明:花色顺序:%c<%c<%c<%c, 面值顺序%d<%d<...<%c<%c<%c<%c", 3, 4, 5, 6, 2, 3, 74, 81, 75, 65);
printf("\n a.用户选择输入扑克牌 b.随机生成扑克牌\n");
printf("\n A.花色优先排序 B.面值优先排序 C.退出系统\n");
for (i = 0; i<100; i++)
{
printf("\n请选择生成扑克牌方式 : \n");
scanf("%c", &cha);
getchar();
switch (cha)
{
case 'a':{
int t;
printf("请输入扑克牌的张数:");
scanf("%d", &t);
getchar();
apoker unsortpoker[100];
manmakepoker(unsortpoker, t);
}break;
case 'b':printf("\n输入扑克张数: \n"); scanf("%d", &N); createpoker(unsortpoker, N); break;
}
getchar();
printf("\n输入要进行的操作:\n");
scanf("%c", &ch);
switch (ch)
{
case'A':huasepresort(unsortpoker, N); break;
case'B':valuepresort(unsortpoker, N); break;
case'C':break;
default:printf("输入有误请重新输入");
printf("\n");
}
}
}