SWUST OJ 1027.舞伴问题

1027. 舞伴问题

题目链接-1027. 舞伴问题
在这里插入图片描述
解题思路

用STL里面的queue实现出队跳舞跳完舞归队两个过程循环即可

附上代码

#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=1e5+5;
typedef long long ll;
typedef pair<int,int> PII;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	int m;
	char c;
	cin>>m;
	queue<char> q_1;
	queue<char> q_2;
	for(int i=0;i<m;i++){
		cin>>c;
		q_1.push(c);//入队
	}
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>c;
		q_2.push(c);
	}
	char a,b;
	cin>>m;
	while(m--){
		a=q_1.front();//取队首元素
		b=q_2.front();
		q_1.pop();//出队跳舞
		q_2.pop();
		q_1.push(a);//跳完舞排到队列的最后
		q_2.push(b); 
	}
	cout<<a<<" "<<b;
	return 0;
}


发布了78 篇原创文章 · 获赞 9 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/Fiveneves/article/details/104536383