输出一样,但是没有找到提交网站,未进行测试。
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
int main(){
string s;
int len;
stack<int> left;
string ans;
while(cin >> s){
ans = "";
len = s.size();
for(int i = 0; i < len; i++){
if(s[i] == '('){
left.push(i);
ans += " ";
}else if(s[i] == ')'){
if(left.empty()){
ans += "?";
}else{
left.pop();
ans += " ";
}
}else{
ans += " ";
}
}
while(!left.empty()){
ans[left.top()] = '$';
left.pop();
}
cout << s << endl;
cout << ans << endl;
}
return 0;
}
京公网安备 11010502036488号