自己模拟了,没有交过,不知道是否正确。
#include<iostream>
#include<queue>
#include<stack>
#define max 10
using namespace std;
int main()
{
queue<int>player1;
queue<int>player2;
stack<int>table;
bool ontable[max];
int n,m,times,i,data,temp;
while(cin>>n>>m>>times)
{
for(i=0;i<n;i++)
{
cin>>data;
player1.push(data);
}
for(i=0;i<m;i++)
{
cin>>data;
player2.push(data);
}
for(i=0;i<times;i++)
{
if(i%2==0)
{
if(!ontable[player1.front()])
{
ontable[player1.front()]=1;
table.push(player1.front());
player1.pop();
}
else
{
temp=player1.front();
player1.push(temp);
player1.pop();
while(table.top()!=temp)
{
player1.push(table.top());
table.pop();
}
player1.push(table.top());
table.pop();
ontable[player1.front()]=0;
}
}
else
{
if(!ontable[player2.front()])
{
ontable[player2.front()]=1;
table.push(player2.front());
player2.pop();
}
else
{
temp=player2.front();
player2.push(temp);
player2.pop();
while(table.top()!=temp)
{
cout<<player2.back()<<endl;
player2.push(table.top());
table.pop();
}
player2.push(table.top());
table.pop();
ontable[player2.front()]=0;
}
}
}
cout<<player1.size()<<" "<<player2.size()<<endl;
}
return 0;
}