((ABCD(x) )(rttyy())sss)(
((ABCD(x) $$ )(rttyy())sss)( ? ?$
题目可以用递归法进行解决,但是思考了一下,发现还是用二重遍历来的方便。
1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() { 4 string s; 5 while(cin>>s) { 6 cout<<s<<endl; 7 int len=s.length(); 8 for(int i=0; i<len; i++) { 9 for(int j=i-1; j>=0; j--) { 10 if(s[i]==‘)‘&&s[j]==‘(‘) { 11 s[i]=s[j]=‘ ‘; 12 } 13 } 14 } 15 for(int i=0; i<len; i++) { 16 if(s[i]==‘)‘)cout<<"?"; 17 else if(s[i]==‘(‘)cout<<"$"; 18 else cout<<" "; 19 } 20 cout<<endl; 21 } 22 return 0; 23 }
原文:https://www.cnblogs.com/aiqinger/p/12576626.html