文章
246
粉丝
0
获赞
1202
访问
193.5k
#include<iostream>
#include<stack>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=1010;
char s[N];
char a[N];
int main()
{
while(cin.getline(s,N))
{
//cin.ignore();
int len=strlen(s);
stack<int> st;
cout<<s<<endl;
memset(a,' ',sizeof a);
for(int i=0;i<len;i++)
{
if(s[i]=='(')
st.push(i);
else if(s[i]==')')
{
if(st.empty())
a[i]='?';
else if(s[st.top()]!='(')
a[i]='?';
else
st.pop();
}
}
while(!st.empty())
{
int pos=st.top();
st.pop();
a[pos]='$';
}
for(int i=0;i<len;i++)
cout<<a[i];
puts("");
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发