C语言,Dev和VS样例都过了,但是在洛谷上面我的栈的语法有问题。
#include<stdio.h>
#include<stdlib.h>
typedef struct N {
int size;
char* top;
char* base;
}N;
N CSH(N l) {
l.top = l.base = new char[255];
l.size = 255;
return l;
}
int PUSH(N l, char e) {
if (l.top - l.base == l.size) {
return 0;
}
*l.top++ = e;
return 1;
}
int POP(N l) {
if (l.top == l.base) {
return 0;
}
else {
l.top--;
return 1;
}
}
int main() {
N l;
int t, b = 0;
l = CSH(l);
char a;
while(a!='@'){
scanf("%c",&a);
if (a == '(' ) {
PUSH(l, a);
b++;
}
else {
if (a == ')') {
if (b != 0) {
POP(l);
b--;//
}else{
PUSH(l,a);
}
}
}
}
if (l.top == l.base) {
printf("YES");
}
else {
printf("NO");
}
return 0;
}