#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include <vector>
#include<queue>
#include<stack>
using namespace std;
stack<char> myStack;
int main(){
string str;
while(cin>>str){
stack<int> brackets;
string answer(str.size(),' ');
for(int i = 0; i < str.size(); i++){
if(str[i] == '('){//左括号入栈
brackets.push(i);
answer[i] = str[i];
}
else if(str[i] == ')'){//右括号如果栈不为空,则匹配成功
if(!brackets.empty()){
brackets.pop();
answer[i] = str[i];
//answer[i] = 'Y';
}
else{//否则右括号匹配失效
answer[i] = '?';
}
}else{
answer[i] = str[i];
}
}
while(!brackets.empty()){//最终栈不为空则左括号匹配失效
int top = brackets.top();
brackets.pop();
answer[top] = '#';
}
for(int i = 0; i<str.size();i++){
cout<<answer[i]<<" ";
}
cout<<endl;
}
return 0;
}
03-26
809
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)