/*思路寻找是否比配
1寻找的方法是什么
2.是什么时候寻找
3是找的对不对*/
#include
int brace=0,brack=0,paren=0;
void in_quote(int c);
void in_comment(void);
void search(int c);
int main(void)
{
extern int brace,brack,paren;
int c;
while((c=getchar())!='%')
{
if(c=='/')
{
if((c=getchar())=='*')
{
in_comment();
}else{
search(c);
}
}else if(c=='\''||c=='"'){
in_quote(c);
}else{
search(c);
}
if(brace<0)
{
printf("Unbalanced braces\n");
brace=0;
}else if(brack<0)
{
printf("Unbalanced brackets\n");
brack=0;
}else if(paren<0)
{
printf("Unbalanced parentheses\n");
paren=0;
}
}
if(brace>0)
{
printf("Unbalanced braces\n");
}
if(brack>0)
{
printf("Unbalanced brackets\n");
}
if(paren>0)
{
printf("Unbalanced parentheses\n");
}
}
void search(int c)
{
extern int brace,brack,paren;
if(c=='{'){
++brace;
}else if(c=='}'){
--brace;
}else if(c=='['){
++brack;
}else if(c==']'){
--brack;
}else if(c=='('){
++paren;
}else if(c==')'){
--paren;
}
}
void in_comment(void){
int c,d;
c=getchar();
d=getchar();
while(c!='*'||d!='/'){
c=d;
d=getchar();
}
}
void in_quote(int c)
{
int d;
while((d=getchar())!=c)
{
if(d=='\\'){
getchar();
}
}
}