#include<stdio.h>
#define QueueSize 20
typedef struct {
char name[QueueSize];
char sex;
}Person;typedef struct {
Person *dancer;
int front;
int rear;
int count;
} CirQueue;void InitQueue(CirQueue *Q)
{
Q->front=Q->rear=0;
Q->count=0;
}int QueueEmpty(CirQueue *Q)
{
return Q->count==0;
}int QueueFull(CirQueue *Q)
{ return Q->count == QueueSize;
}Person QueueFront(CirQueue *Q)
{
if(QueueEmpty(Q)) printf("The queue is empty.\n");
return Q->dancer[Q->front];
}void EnQueue(CirQueue *Q,Person dancer)
{
if(QueueFull(Q)) printf("Team full!\n");
Q->count++;
Q->dancer[Q->rear]=dancer;
Q->rear=(Q->rear+1)%QueueSize;
}Person DeQueue(CirQueue *Q)
{
Person temp;
if(QueueEmpty(Q))printf("Team empty!\n");
temp=Q->dancer[Q->front];
Q->count--;
Q->front=(Q->front+1)%QueueSize;
return temp;
}void DancePartners(Person *dancer, int num)
{ int i;
Person P;
CirQueue Mdancers, Fdancers;
InitQueue(&Mdancers);
InitQueue(&Fdancers);
for(i=0;i<num;i++) {
P=dancer[i];
if(P.sex=='F') EnQueue(&Fdancers, P);
else EnQueue(&Mdancers, P);
}
printf("The partner mix is:\n");while(!QueueEmpty(&Fdancers)&&!QueueEmpty(&Mdancers)) {
P=DeQueue(&Fdancers);
printf("%s,",P.name);
P=DeQueue(&Mdancers);
printf("%s\n",P.name);
}if(!QueueEmpty(&Fdancers)) {
printf("There are %d women in the waiting.\n",Fdancers.count);
P=QueueFront(&Fdancers);
printf("The first waiting's woman is:%s.\n", P.name);
}
if(!QueueEmpty(&Mdancers)) {
printf("There are %d men in the waiting.\n",Mdancers.count-1);
P=QueueFront(&Mdancers);
printf("The first waiting's man is:%s.\n", P.name);
}
}int main()
{
int i,j;
Person dancer[QueueSize];
printf("\n Please enter the number of the dances:");
scanf("%d",&j);
while(j<=0)
{
printf("Input error, please input again:");
scanf("%d",&j);
}
for(i=1;i<=j;i++)
{
printf("Please input the %d honored person's name :",i);
scanf("%s",&dancer[i-1].name);
printf("Please input the %d honored person's sex (F/M):",i);
scanf("%s",&dancer[i-1].sex);
while(dancer[i-1].sex!='F'&&dancer[i-1].sex!='M')
{
printf("Input error, please input again:");
scanf("%s",&dancer[i-1].sex);
}
}
DancePartners(dancer,i);
}
#define QueueSize 20
typedef struct {
char name[QueueSize];
char sex;
}Person;typedef struct {
Person *dancer;
int front;
int rear;
int count;
} CirQueue;void InitQueue(CirQueue *Q)
{
Q->front=Q->rear=0;
Q->count=0;
}int QueueEmpty(CirQueue *Q)
{
return Q->count==0;
}int QueueFull(CirQueue *Q)
{ return Q->count == QueueSize;
}Person QueueFront(CirQueue *Q)
{
if(QueueEmpty(Q)) printf("The queue is empty.\n");
return Q->dancer[Q->front];
}void EnQueue(CirQueue *Q,Person dancer)
{
if(QueueFull(Q)) printf("Team full!\n");
Q->count++;
Q->dancer[Q->rear]=dancer;
Q->rear=(Q->rear+1)%QueueSize;
}Person DeQueue(CirQueue *Q)
{
Person temp;
if(QueueEmpty(Q))printf("Team empty!\n");
temp=Q->dancer[Q->front];
Q->count--;
Q->front=(Q->front+1)%QueueSize;
return temp;
}void DancePartners(Person *dancer, int num)
{ int i;
Person P;
CirQueue Mdancers, Fdancers;
InitQueue(&Mdancers);
InitQueue(&Fdancers);
for(i=0;i<num;i++) {
P=dancer[i];
if(P.sex=='F') EnQueue(&Fdancers, P);
else EnQueue(&Mdancers, P);
}
printf("The partner mix is:\n");while(!QueueEmpty(&Fdancers)&&!QueueEmpty(&Mdancers)) {
P=DeQueue(&Fdancers);
printf("%s,",P.name);
P=DeQueue(&Mdancers);
printf("%s\n",P.name);
}if(!QueueEmpty(&Fdancers)) {
printf("There are %d women in the waiting.\n",Fdancers.count);
P=QueueFront(&Fdancers);
printf("The first waiting's woman is:%s.\n", P.name);
}
if(!QueueEmpty(&Mdancers)) {
printf("There are %d men in the waiting.\n",Mdancers.count-1);
P=QueueFront(&Mdancers);
printf("The first waiting's man is:%s.\n", P.name);
}
}int main()
{
int i,j;
Person dancer[QueueSize];
printf("\n Please enter the number of the dances:");
scanf("%d",&j);
while(j<=0)
{
printf("Input error, please input again:");
scanf("%d",&j);
}
for(i=1;i<=j;i++)
{
printf("Please input the %d honored person's name :",i);
scanf("%s",&dancer[i-1].name);
printf("Please input the %d honored person's sex (F/M):",i);
scanf("%s",&dancer[i-1].sex);
while(dancer[i-1].sex!='F'&&dancer[i-1].sex!='M')
{
printf("Input error, please input again:");
scanf("%s",&dancer[i-1].sex);
}
}
DancePartners(dancer,i);
}
解决方案 »
- 用java编写一个显示三角形数字表的程序
- Java 在drawString(String)时怎样处理带有HTML的String
- 如何学好javaSE?
- java中的copy文件程序
- 访问JNI类的问题,有包类访问无包类
- 关于JAVA数据库的问题 在线等
- 关于页面显示目录结构的问题,急啊~~~~~~~~~
- 大家看这个程序,请问,子类overWrite 父类的方法,形参一定要一样吗?构造函数和普通函数的覆盖有没有区别?
- 构造器
- ClassLoader的问题,高手进来!
- synchronized加在方法前,锁作用范围?
- 请教有没有socket通信层开发的例子,博客也行,要有同步处理,异步提供回调方法等的,不要一个简单的聊天室例子
居然还能看懂简单的 c++
代码
看来当年大学没白学呀。。
哈哈