#include<stdio.h>
#include<stdlib.h>
int main()
{
intch = 0;
int count = 0;
while((ch = getchar()) != EOF)
{
if(ch == '{')
{
count++;
}
if(ch == '}'&&count == 0)
{
printf("花括号不成对出现\n");
}
if(ch == '}')
{
count--;
}
}
if(count == 0)
{
printf("花括号成对出现\n");
}
else
{
printf("花括号不成对出现\n");
}
system("pause");
return 0;
}
检测花括号配对
本文介绍了一个简单的C程序,用于检测输入文本中花括号的配对情况。通过逐字符读取并计数,判断花括号是否正确闭合。
1014

被折叠的 条评论
为什么被折叠?



