头文件#include<st
括号匹配题:
#include<stdio.h>
#include<stack>
#include<string.h>
using namespace std;
int main()
{
stack<int> s;//定义一个堆栈
char str[110];
char ans[110];
int i;
while(scanf("%s",str)!=EOF)
{
for(i=0;i<strlen(str);i++)
{
if(str[i]=='(')
{
s.push(i);//数组下标放入堆栈中
ans[i]=' ';
}
else if(str[i]==')')
{
if(s.empty()==false)//不空则出栈
{
s.pop();
ans[i]=' ';
}
else
ans[i]='?';
}
else
ans[i]=' ';
}
while(!s.empty())
{
ans[s.top()]='$';
s.pop();
}
ans[i]='\0';
puts(str);
puts(ans);
}
return 0;
}