#include<stdio.h>
int main(){
char s[101];
while(scanf("%s",s)!=EOF){
printf("%s\n",s);
char tem[101];
int a[101]={0};
int top=0;
int i=0;
for(;s[i]!='\0';i++){
if(s[i]=='('){
tem[top++]=s[i];
a[i]=-1;
}else if(s[i]==')'){
if(top==0||tem[top-1]!='('){
a[i]=-2;
}else{
a[i]=0;
int j=i;
for( ;j>=0;j--){
if(a[j]==-1) break;
}
a[j]=0;
top--;
}
}else{
a[i]=0;
}
}
for(int j =0;j<i;j++){
if(a[j]==0){
printf(" ");
}else if(a[j]==-1){
printf("$");
}else{
printf("?");
}
}
printf("\n");
}
return 0;
}
结果:
标签:匹配,tem,1978,int,top,扩号,else,char,101 From: https://www.cnblogs.com/llllmz/p/17973240