#include"SqQueue.h"
#include <iostream>
using namespace std;
void DancePartner(Person dancer[],int num)
{
SqQueue Mdancers, Fdancers;
/**************Begin********************/
Person p;
InitQueue(Mdancers);
InitQueue(Fdancers);
for(int i=0;i<num;i++)
{
p=dancer[i];
if(p.sex=='F')EnQueue(Fdancers,p);
else
EnQueue(Mdancers,p);
}
cout<<"The dancing partners are:"<<endl;
while(!QueueEmpty(Fdancers)&&!QueueEmpty(Mdancers))
{
DeQueue(Fdancers,p);
cout<<p.name<<" ";
DeQueue(Mdancers,p);
cout<<p.name<<endl;
num-=2;
}
if(!QueueEmpty(Fdancers))
{
p=GetHead(Fdancers);
cout<<num<<" women are left,"
<<"The first woman to get a partner is:"<<p.name<<endl;
}
else if(!QueueEmpty(Mdancers))
{
p=GetHead(Mdancers);
cout<<num<<" men are left,"
<<"The first man to get a partner is:"<<p.name<<endl;
}
/**************End********************/
}
int main()
{
/********************Begin***************************/
int a;
Person b[100];
cin>>a;
for(int i=0;i<a;i++)
cin>>b[i].name>>b[i].sex;
DancePartner(b,a);
/********************End*****************************/
return 0;
}
第4关:舞伴问题
最新推荐文章于 2023-10-26 13:56:50 发布