学会stack(栈)还是能轻松解决一些题目
#include<bits/stdc++.h>
using namespace std;
int main()
{
stack <char> sk;
string str;
getline(cin,str);
int i=0;
while(str[i]!='\0')
{
char ch=str[i];
if(ch=='('||ch==')'||ch=='{'||ch=='}'||ch=='['||ch==']'||ch=='<'||ch=='>')
{
if(sk.empty())
{
sk.push(ch);
}
else if((ch==')'&&sk.top()=='(')||(ch==']'&&sk.top()=='[')||(ch=='}'&&sk.top()=='{')||(ch=='>'&&sk.top()=='<'))
{
sk.pop();
}
else
sk.push(ch);
}
i++;
}
if(sk.empty())
cout<<"yes";
else
cout<<"no";
}