题目地址:http://ac.jobdu.com/problem.php?cid=1040&pid=25
C语言源码:
#include<stdio.h>
#include<string.h>
typedef struct stack
{
int num;
char cha;
}stack;
int main()
{
char a[102],b[102];
stack s[102];
int i,n,top;
while(scanf("%s",a)!=EOF)
{
getchar();
n=(int)strlen(a);
for(i=0;i<n;i++)
b[i]=' ';
b[n]='\0';
i=0;
top=0;
while(i<n)
{
if(a[i]=='(')
{
s[top].num=i;
s[top++].cha=a[i];
b[i]='$';
}
else
if(a[i]==')')
{
if(top&&s[top-1].cha=='(')
{
top--;
b[s[top].num]=' ';
}
else
{
s[top].num=i;
s[top++].cha=a[i];
b[i]='?';
}
}
i++;
}
printf("%s\n%s\n",a,b);
}
}