求助站外题
  • 板块学术版
  • 楼主Literally
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/3/22 21:09
  • 上次更新2023/10/23 20:49:50
查看原帖
求助站外题
638141
Literally楼主2023/3/22 21:09

RT

主要不知道什么时候输出-1,其他都会了

不输出-1的90分代码:

#include <bits/stdc++.h>
using namespace std;
int n,k1,k2,temp,huihe=0;
queue <int> k1pai;
queue <int> k2pai;
int main(){
	cin>>n>>k1;
	for(int i=1;i<=k1;i++){
		cin>>temp;
		k1pai.push(temp);
	}
	cin>>k2;
	for(int i=1;i<=k2;i++){
		cin>>temp;
		k2pai.push(temp);
	}
	while(!k1pai.empty() && !k2pai.empty()){
		if(k1pai.front()>k2pai.front()){
			huihe++;
			k1pai.push(k2pai.front());
			k1pai.push(k1pai.front());
			k1pai.pop();
			k2pai.pop();
		}else{
			huihe++;
			k2pai.push(k1pai.front());
			k2pai.push(k2pai.front());
			k1pai.pop();
			k2pai.pop();
		}
	}
	cout<<huihe<<' ';
	if(k1pai.empty()){
		cout<<2;
	}else{
		cout<<1;
	}
	return 0;
}
2023/3/22 21:09
加载中...