假设在周末舞会上,男士们和女士们进入舞厅时,各自排成一队。跳舞开始时,依次从男队和女队的队头上各出一人配成舞伴。若两队初始人数不相同,则较长的那一队中未配对者等待下一轮舞曲。要求编写程序实现舞伴问题。
Description
输入一共5行,
第一行是男生人数m;
第二行依次是男生的姓名;
第三行是女士的人数n;
第四行依次是女士的姓名;
第五行是跳舞的轮数。
Input
配对的男士和女士的姓名。
配对的男士和女士的姓名。
Output
5
A B C D E
3
F G H
2
Sample Input
B G
这个题也蛮坑的==, 试了好几次才读懂什么意思,就是求最后一轮跳舞的一对人是谁,每一轮男女分别只能上一个人,这个题目描述也是醉
#include<iostream>
#include<string>
#include<cstdlib>
#include<list>
#include<stack>
#include<queue>
#include<stdio.h>
using namespace std;
int main()
{
int man_n;
while (cin >> man_n)
{
string p;
queue<string>man;
for (int i = 0; i < man_n; i++)
{
cin >> p;
man.push(p);
}
int woman_n;
cin >> woman_n;
queue<string>woman;
for (int i = 0; i < woman_n; i++)
{
cin >> p;
woman.push(p);
}
int time;
cin >> time;
int temp;
man_n > woman_n ? temp = woman_n : temp = man_n;
for (int j = 1; j < time; j++)
{
string now_man = man.front();
string now_woman = woman.front();
man.pop();
woman.pop();
man.push(now_man);
woman.push(now_woman);
}
string nman = man.front();
string nw = woman.front();
cout << nman << ' ' << nw;
}
return 0;
}//by swust_t_p
转载请注明原文地址: https://ju.6miu.com/read-25466.html