链接
题解
题目说从左往右合并,那我就从左往右合并,前缀合并完的序列存起来,然后现在把一个泡泡从右端加入,如果可以和右端产生关系那就操作一下,以此往复。
代码
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define iinf 0x3f3f3f3f
#define linf (1ll<<60)
#define eps 1e-8
#define maxn 1000010
#define maxe 1000010
#define cl(x) memset(x,0,sizeof(x))
#define rep(i,a,b) for(i=a;i<=b;i++)
#define drep(i,a,b) for(i=a;i>=b;i--)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define de(x) cerr<<#x<<" = "<<x<<endl
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll read(ll x=0)
{
ll c, f(1);
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-f;
for(;isdigit(c);c=getchar())x=x*10+c-0x30;
return f*x;
}
vector<char> stk;
char s[maxn];
int main()
{
int i, n;
while(~scanf("%s",s+1))
{
stk.clear();
n=strlen(s+1);
rep(i,1,n)
{
char c=s[i];
while(!stk.empty() and stk.back()==c)
{
if(c=='o')stk.pop_back(), c='O';
else stk.pop_back(), c='*';
}
if(c!='*')stk.emb(c);
}
for(auto c:stk)putchar(c);
putchar(10);
rep(i,1,n)s[i]=0;
}
return 0;
}