洛谷原题٩(*Ӧ)و写的全对
2023-07-26 08:55:19
发布于:浙江
20阅读
0回复
0点赞
#include<iostream>
#include<cstring>
#include<stack>
#include<queue>
using namespace std;
stack<char> st;
bool check(char a,char b)
{
if(a=='('&&b==')')
{
return 1;
}
return 0;
}
int main()
{
string str;
cin>>str;
int size=str.size();
for(int i=0;i<size;i++)
{
if(str[i]'('||str[i]')')
{
if(st.empty())
{
st.push(str[i]);
}
else
{
if(check(st.top(),str[i]))
{
st.pop();
}
else
{
st.push(str[i]);
}
}
}
}
if(st.empty())
{
cout<<"YES";
}
else
{
cout<<"NO";
}
return 0;
}
这里空空如也
有帮助,赞一个