文章
35
粉丝
0
获赞
144
访问
7.3k
#include <bits/stdc++.h>
using namespace std;
void isValid(string s){
stack<char> st;
vector<char> v(s.length(),' ');
for(int i=0;i<s.length();i++){
char c=s[i];
if(c=='('){
st.push(i);//入栈索引
}
else if(c==')'){
if(st.empty()){
v[i]='?';
}else{
st.pop();
}
}
}
while(!st.empty()){
int index=st.top();
v[index]='$';
st.pop();
}
cout<<s<<endl;
for(char c: v){
cout<<c;
}
cout<<endl;
}
int main() {
string s;
while(getline(cin,s)){
isValid(s);
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发