共回答了12个问题采纳率:91.7%
#includetypedef struct que{
int *qu;
int front,rear;
}Squeue;
void Initqueue(Squeue *q,int len);
void Enqueue(Squeue *q,int n,int len);
int Dequeue(Squeue *q,int len);
int main()
{ int m,n,x,y,i,j,num=0;
Squeue q1,q2;
scanf("%d%d",&m,&n);//Input m and n;
Initqueue(&q1,m);
Initqueue(&q2,n);
for(i=0;iqu=(int*)malloc(len*sizeof(int)) ;
if(!q->qu) exit(0);
q->front=q->rear=0;}
void Enqueue(Squeue *q,int n,int len)
{q->qu[q->rear]=n;
q->rear=(q->rear+1)%len;
}
int Dequeue(Squeue *q,int len)
{int e;
e=q->qu[q->front];
q->front=(q->front+1)%len;
return e;
}在dev和win_tc中通过,在用队列的时候,没有考虑特殊情况,没影响。下面未用队列的算法似乎是很简单,也可以在dev 和win_tc上通过
#include
int main()
{ int m,n;
int i,j,k=0;
int x,y;
printf("Input the number of ladies and gentlemen:");
scanf("%d%d",&m,&n);
printf("Input the location of the man and the woman:");
scanf("%d%d",&x,&y);
if(m==n&&x!=y) printf("No chance!");
else
{for(i=0,j=0;!(i==x&&j==y);i=(i+1)%m,j=(j+1)%n)
{printf("man(%d)woman(%d)n",i+1,j+1); k++;}
printf("nThe number of song is:%dn",k);
}
system("pause");
return 0;
}
1年前
5
编程实现舞伴问题 c语言 C语言实现舞伴问题(队列)假设在周末舞会上 男士们(m人)和女士们(n人)进入舞厅时 各自排成一队。跳舞开始时 依次从男...
如果觉得《编程实现舞伴问题 c语言 C语言实现舞伴问题(队列)假设在周末舞会上 男士们(m人》对你有帮助,请点赞、收藏,并留下你的观点哦!