大模拟
2025-07-17 15:56:07
发布于:北京
4阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int main()
{
string x,y;
cin>>x>>y;
queue<char> a;//玩家A
queue<char> b;//玩家B
for (int i=0;i<x.size();i++)
{
a.push(x[i]);
}
for (int i=0;i<y.size();i++)
{
b.push(y[i]);
}
string ans;//出的牌
int cnt=0;//出牌次数
bool _a=1;//是不是a出牌
while(!a.empty() && !b.empty())
{
if (cnt>=10000)//题目要求
{
cout<<-1;
return 0;
}
if(_a)//是A的回合
{
if (a.empty())
{
break;
}
char c=a.front();//取第一张牌
size_t pos=ans.find(c);//找已经出过的牌里有没有和要出的牌相同的
cnt++;
if (pos==string::npos)//没找到
{
ans+=c;//出
a.pop();//出
_a=0;//出完了
}
else
{
a.pop();//依旧出/.
string momo=ans.substr(pos)+c;//从找到的位置到出的牌
reverse(momo.begin(),momo.end());//逆序
for (auto it=momo.begin();it!=momo.end();it++)
{
a.push(*it);//回收牌
}
ans=ans.substr(0,pos);//在牌桌上的牌减少
}
if (a.empty())
{
break;//结束
}
}
else//对B的处理和对A的处理几乎相同
{
if (b.empty())
{
break;//111
}
char c=b.front();
size_t pos=ans.find(c);
cnt++;
if(pos==string::npos)
{
ans+=c;
b.pop();//出牌这一块/.
_a=1;
}
else
{
b.pop();
string momo=ans.substr(pos)+c;
reverse(momo.begin(),momo.end());
for (auto it=momo.begin();it!=momo.end();it++)
{
b.push(*it);
}
ans=ans.substr(0,pos);
}
if(b.empty())
{
break;
}
}
}
if (a.empty())//爽爽输出
{
while(!b.empty())
{
cout<<b.front();
b.pop();
}
}
else
{
while(!a.empty())
{
cout<<a.front();
a.pop();
}
}
return 0;//好习惯不要忘
}
全部评论 1
哇,太牛逼了
1周前 来自 河北
0
有帮助,赞一个