如果没有任何输入,那么直接输出No
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
int main()
{
char ch;
int fact;
scanf("%c",&ch);
if(ch=='\n')
{
printf("No\n");
return 0;
}
fact=0;
stack<char>s;
while(ch!='\n')
{
switch(ch)
{
case '[':
s.push(ch);
break;
case '(':
s.push(ch);
break;
case ']':
if(s.empty()==true)
{
fact=1;
}
else if(s.top()=='[')
{
s.pop();
}
else
{
fact=1;
}
break;
case ')':
if(s.empty()==true)
fact=1;
else if(s.top()=='(')
{
s.pop();
}
else
{
fact=1;
}
break;
}
scanf("%c",&ch);
if(fact==1)
{
printf("No\n");
return 0;
}
}
if(s.empty()==false )
printf("No\n");
else
printf("Yes\n");
return 0;
}