一. 编写一个程序,它从标准输入读取C源代码,并验证所有的花括号都正确的成对出现
#include<stdio.h>
#include<Windows.h>#include<stdlib.h>
int main()
{
char ch;
int count = 0;
while ((ch = getchar()) != EOF)
{
if (ch == '{')
count++;
else if (ch == '}' && 0 != count)
{
count--;
}
else if (ch == '}' && 0 == count)
{
printf("不匹配\n");
return 0;
}
}
if (0 == count)
{
printf("匹配\n");
system("pause");
}
return 0;
}