挺有意思的题目,解题如下:
#include <stdio.h>
int main() {
int ch;
int braces;
braces = 0;
while ((ch = getchar()) != EOF) {
if (ch == '{')
{
braces += 1;
}
if (ch == '}')
{
if (braces == 0)
{
printf("Extra closing brace!\n");
} else {
braces -= 1;
}
}
}
if (braces > 0)
{
printf("%d unmatched opening braces!\n", braces);
}
return 0;
}