
代码(新手上路实在是有一个测试点不知道是啥 就是过不了题 )
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;struct SNode {
char ch[1005];
char *Data = ch;
int Top = -1;
int MaxSize = 1000;
};void push(char ch,SNode &Stack){
Stack.Data[++Stack.Top] = ch;
}void pop(SNode &Stack){
Stack.Top --;
}int get_top(SNode &Stack){
return Stack.Data[Stack.Top];
}bool Empty(SNode &Stack){
return Stack.Top == -1;
}
int main()
{
SNode Stack;
char ch;
int num = 0,left = 0,right = 0;
while(scanf("%c",&ch) && ch != '\n'){
// InitStack(Stack);
switch(ch){
case '(':
push(ch,Stack);
left++;
break;
case '{':
push(ch,Stack);
left++;
break;
case '[':
push(ch,Stack);
left++;
break;
case ')':
if(get_top(Stack) == '('){
pop(Stack);
num++;
}
right++;
break;
case '}':
if(get_top(Stack) == '{'){
pop(Stack);
num++;
}
right++;
break;
case ']':
if(get_top(Stack) == '['){
pop(Stack);
num++;
}
right++;
break;
}
}
cout<<left<<" "<<right<<endl;
if(Empty(Stack)){
cout<<"YES"<<endl;
}
else
cout<<"NO";
return 0;
}