题解
很有意思的思想,一遇到括号就倒过来
code
#include<bits/stdc++.h>
#define ll long long
#define lb long double
#define lowbit(x) ((x)&(-x))
using namespace std;
const ll inf=1e18;
const ll mod=1e9+7;
const ll N=4e5;
ll qpow(ll a,ll n)
{
ll res=1;
while(n)
{
if(n&1) res=res*a%mod;
a=a*a%mod;
n>>=1;
}
return res;
}
ll inv(ll x)
{
return qpow(x,mod-2);
}
ll fa[2000005];
ll finds(ll now){return now==fa[now]?now:finds(fa[now]);}
vector<ll> G[200005];
ll dfn[200005],low[200005];
ll cnt=0,num=0;
ll in_st[200005]={0};
stack<ll> st;
ll belong[200005]={0};
void scc(ll now,ll fa)
{
dfn[now]=++cnt;
low[now]=dfn[now];
in_st[now]=1;
st.push(now);
for(auto next:G[now])
{
if(next==fa) continue;
if(!dfn[next])
{
scc(next,now);
low[now]=min(low[now],low[next]);
}
else if(in_st[next])
{
low[now]=min(low[now],dfn[next]);
}
}
if(low[now]==dfn[now])
{
ll x;
num++;
do
{
x=st.top();
st.pop();
in_st[x]=0;
belong[x]=num;
}while(x!=now);
}
}
int trans[500005];
void solve()
{
string s;
cin>>s;
int n=s.size();
stack<int> st;
for(int i=0;i<n;i++)
{
if(s[i]=='(') st.push(i);
else if(s[i]==')')
{
int last=st.top();
st.pop();
trans[last]=i;
trans[i]=last;
}
}
int step=1,sum=0,tem=0,id=0;
while(tem<n)
{
if(s[id]=='('||s[id]==')')
{
id=trans[id];
step=-step;
sum++;
}
else
{
if(sum%2==0)
{
cout<<s[id];
}
else
{
if(s[id]>='a'&&s[id]<='z') cout<<(char)(s[id]-'a'+'A');
else cout<<(char)(s[id]-'A'+'a');
}
}
id+=step;
tem++;
}
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int TT=1;
//cin>>TT;
while(TT--) solve();
return 0;
}
标签:ll,Transpose,next,dfn,low,st,now
From: https://www.cnblogs.com/pure4knowledge/p/18341786