标签:
3 [(]) (]) ([[]()])
No No Yes
代码:
01.
#include<stdio.h>
02.
#include<string.h>
03.
char
m[10010],n[10010];
04.
int
top;
05.
void
push(
char
x){top++;
06.
m[top]=x;
07.
}
08.
void
pop(
char
*x){*x=m[top];
09.
top--;
10.
}
11.
int
main(){
12.
int
T,i,flot;
char
temp;
13.
scanf
(
"%d"
,&T);
14.
while
(T--){i=top=0;flot=1;
15.
memset
(m,0,
sizeof
(m));
16.
scanf
(
"%s"
,n);
17.
while
(n[i]){
18.
if
(n[i]==
‘[‘
||n[i]==
‘(‘
)push(n[i]);
19.
else
{pop(&temp);
20.
if
(temp==
‘(‘
&&n[i]==
‘]‘
)flot=0;
21.
if
(temp==
‘[‘
&&n[i]==
‘)‘
)flot=0;
22.
}
23.
/* printf("%d m[%d]=%c ",i,top,m[top]);*/
i++;
24.
}
if
(top!=0)flot=0;
25.
if
(flot)
printf
(
"Yes\n"
);
26.
else
printf
(
"No\n"
);
27.
}
28.
return
0;
29.
}
01.
#include<stdio.h>
02.
#include<string.h>
03.
char
m[10010],n[10010];
04.
int
top;
05.
void
push(
char
x){top++;
06.
m[top]=x;
07.
}
08.
void
pop(){
09.
top--;
10.
}
11.
int
main(){
12.
int
T,i;
13.
scanf
(
"%d"
,&T);
14.
while
(T--){i=top=0;
15.
memset
(m,0,
sizeof
(m));
16.
scanf
(
"%s"
,n);
17.
while
(n[i]){
18.
if
(n[i]==
‘]‘
&&m[top]==
‘[‘
)pop();
19.
else
if
(n[i]==
‘)‘
&&m[top]==
‘(‘
)pop();
20.
else
push(n[i]);
21.
/* printf("%d m[%d]=%c ",i,top,m[top]);*/
i++;
22.
}
23.
if
(top==0)
printf
(
"Yes\n"
);
24.
else
printf
(
"No\n"
);
25.
}
26.
return
0;
27.
}
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4585835.html