#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main()
{
stack<char> w;
string str;
cin >> str;
int len =str.size();
int i = 0;
int num = 0;
while (len--)
{
if (str[i] == ')'&&w.size()!=0)
{
w.pop();
num++;
}
else
w.push(str[i]);
i++;
}
printf("%d", num);
system("pause");
return 0;
}
C++ stack 匹配括号
最新推荐文章于 2024-07-23 11:49:26 发布