自己模拟了,没有交过,不知道是否正确。
#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;
}
这是一个简单的卡片游戏模拟程序,使用 C++ 实现。程序通过两个玩家轮流放置卡片到桌面上,并检查是否有重复的卡片。若有重复,则该玩家需收回之前放置的所有卡片。此模拟涉及队列和栈的数据结构。

被折叠的 条评论
为什么被折叠?



