栈
2026-03-10 20:26:06
发布于:广东
4阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
stack<char> s;
string str;
bool check(string str)
{
int len=str.size();
for(int i=0;i<len;i++)
{
switch(str[i])
{
case ']':
if(s.top()!='[') return false;
if(!s.empty()) s.pop();
break;
case ')':
if(s.top()!='(') return false;
if(!s.empty()) s.pop();
break;
case '}':
if(s.top()!='{') return false;
if(!s.empty()) s.pop();
break;
default: s.push(str[i]);
}
}
return s.size()==0;
}
int main()
{
cin>>str;
string ans=check(str)?"true":"false";
cout<<ans;
return 0;
}
不点赞的人是gay 或 拉拉
这里空空如也





有帮助,赞一个