#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main() {
stack<int> stack;
string s;
int flag[101] = {0};
//while(scanf("%s", str) != EOF)
while (cin >> s) {
int l = s.length();
for (int i = 0; i < l; i++) {
if (s[i] == '(') {
stack.push(i);
}
else if (s[i] == ')') {
if (!stack.empty()) {
int h = stack.top();
if (s[h] == '(') {
stack.pop();
} else {
flag[i] = 1;
}
} else {
flag[i] = 1;
}
}
}
while (!stack.empty()) {
flag[stack.top()] = -1;
stack.pop();
}
cout << s << endl;
for (int i = 0; i < l; i++) {
if (flag[i] == -1) {
cout << '$';
}
else if (flag[i] == 1) {
cout <<'?';
}
else {
cout <<' ';
}
flag[i] = 0;
}
cout << endl;
s = "";
}
return 0;
}
括号匹配问题
最新推荐文章于 2022-10-24 21:13:26 发布