设计一个模拟配对系统,逐步演示参加舞会的男士和女士各自排队进入舞厅。
发布网友
发布时间:2022-04-30 04:58
我来回答
共2个回答
热心网友
时间:2023-11-05 16:26
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <list>
#include <string>
using namespace std;
list<string> male,female;
int _tmain(int argc, _TCHAR* argv[])
{
ifstream f("dance.txt");
string sex,name;
while(f>>sex>>name)
{
if(sex=="F")
female.push_back(name);
else if(sex == "M")
male.push_back(name);
}
int ml = male.size();
int fl = female.size();
if(ml>=fl)
{
for(int i=0;i<fl;i++)
{
cout<<male.front()<<" and "<<female.front()<<endl;
male.pop_front();
female.pop_front();
}
if(ml>fl)
cout<<ml-fl<<" waiting male:"<<endl;
for(int i=0;i<ml-fl;i++)
{
cout<<male.front()<<endl;
}
}
else
{
for(int i=0;i<ml;i++)
{
cout<<male.front()<<" and "<<female.front()<<endl;
male.pop_front();
female.pop_front();
}
cout<<fl-ml<<" waiting female:"<<endl;
for(int i=0;i<fl-ml;i++)
{
cout<<female.front()<<endl;
}
}
getchar();
return 0;
}
dance.txt 文件
F nel
M mac
F ll
M sf
M sdf
执行结果
mac and nel
sf and ll
1 waiting male:
sdf
追问我用VC++怎么不行 你用的VS吗 ?
追答是用的vs
热心网友
时间:2023-11-05 16:26
系统,那你是要开发系统
还是要写文字,
你都没详细完整的谈