编写一个程序,它从标准输入读取C源代码,并验证所有的花括号都正确的成对出现。
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <windows.h>
int main()
{
int count = 0;
char ch;
for (int i = 0; i < 10; i++)//假设取10个字符
{
scanf("%c", &ch);//本程序输入必须为10个字符且需要时英文括号
printf("%c", ch);
if (ch == '(')
count++;
if (ch ==')')
count--;
}
if (count == 0)
printf("succeed");
else
printf("failed");
system("pause");
return 0;
}
最基础的括号匹配问题
最新推荐文章于 2019-08-27 21:51:07 发布