-
Notifications
You must be signed in to change notification settings - Fork 1
/
20.c
47 lines (46 loc) · 945 Bytes
/
20.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*************************************************************************
* File Name : 20.c
* Author : unasm
* Mail : unasm@sina.cn
* Last_Modified: 2015-05-07 10:22:11
************************************************************************/
#include<stdio.h>
//#include<boolstd.h>
#include<stdbool.h>
char stack[100000];
bool isValid(char* s) {
char map[300];
for(int i = 0;i < 300;i++) {
map[i] = 0;
}
map[')'] = '(';
map[']'] = '[';
map['}'] = '{';
int top = 0;
for(int i = 0; s[i] != '\0'; i++) {
if (map[s[i]]) {
if (top && stack[top - 1] == map[s[i]] ) {
top --;
} else {
return false;
}
} else {
stack[top++] = s[i];
}
}
if(top == 0) {
return true;
}
return false;
}
int main(int argc, const char *argv[])
{
char sta[] = "{}()";bool expect = true;
bool res = isValid(sta);
if (res == expect) {
printf("yes\n");
} else {
printf("%d\n", res);
}
return 0;
}