本地全过,为啥交到洛谷上就全WA?
#include<bits/stdc++.h>
using namespace std;
int w[500010];
stack<int> stk;
int main(){
string s;
cin>>s;
int n=s.length();
memset(w,0,sizeof(w));
for(int i=0;i<n;i++){
if(s[i]=='(')stk.push(i);
if(s[i]==')'){
int t=stk.top();
stk.pop();
w[i]=t;
w[t]=i;
}
}
int now=-1,dir=1;
while(now<n){
now+=dir;
if(s[now]=='(' || s[now]==')'){
now=w[now];
dir=-dir;
}else{
if(dir<0)cout<<char(s[now]>='A' && s[now]<='Z'?s[now]+32:s[now]-32);
else cout<<s[now];
}
}
return 0;
}