简单判断表达式括号是否匹配

#include <iostream>
using namespace std;
int main()

{
string s;
cin>>s;
int count=0;
for(int i=0;i<s.length();i++)
{
if(s[i]=='(')
count++;
else if(s[i]==')')
if(count==0)
{
cout<<"not match"<<endl;
return 1;
}
count--;
}
cout<<"match"<<endl;
return 0;
}

用于判断表达式的括号是否匹配。同理可以扩展成判断{}的匹配。

原文地址:https://www.cnblogs.com/lazycoding/p/2312337.html