文章
85
粉丝
0
获赞
601
访问
63.2k
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
while (getline(cin,s)) {
cout<<s<<endl;
int n = s.length();
vector<char> tag(n,' ');
stack <int> st;
for (int i = 0; i < n; i++) {
char c = s[i];
if (c=='(') {
st.push(i);
}
if (c==')') {
if (st.empty()) {
tag[i] = '?';
}
else {
st.pop();
}
}
}
while (!st.empty()) {
int t = st.top();
tag[t]='$';
st.pop();
}
for (int i = 0; i < n; i++) {
cout << tag[i];
}
cout << endl;
}
}
登录后发布评论
暂无评论,来抢沙发