#include<iostream>
using namespace std;
int main()
{
char c;
int count = 0;
while ((c = getchar()) != EOF)
{
if ('{' == c)
{
count++;
}
else if ('}' == c&&0!=count)
{
count--;
}
else if ('}' == c && 0 == count)
{
cout << "不匹配" << endl;
}
}
if (count == 0)
{
cout << "匹配" << endl;
}
else
{
cout << "不匹配" << endl;//不要忘记判断不等于0的情况
}
system("pause");
}
判断输入的文字花括号是否匹配
最新推荐文章于 2023-10-12 11:00:01 发布