主函数(main):
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
int main()
{
int ch;
int count = 0; //定义的计数器
while ((ch = getchar()) != EOF) //EOF 结束标志符
{
if (ch == '{')
{
count++;
}
if (ch == '}' && count == 0)
{
printf("不匹配\n");
system("pause");
return 0;
}
if (ch == '}' && count != 0)
{
count--;
}
}
if (count == 0)
{
printf("匹配!\n");
}
else
{
printf("不匹配!\n");
}
system("pause");
return 0;
}
在写着程序时着实把我吓到了,开始都不知道怎么回事,但是看了一下网上的一下子就明白了,其实就是一个很简单的小程序。