-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2504.cpp
61 lines (49 loc) · 922 Bytes
/
2504.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <cstdio>
#include <cstring>
int main(){
int st[15]; // -2 = '(' , -3 = '['
char str[31];
int top = -1, tmp_ret = 0, ret = 0, tmp = 0;
scanf("%s", str);
for(int i = 0; i < strlen(str); i++){
if(str[i] == '('){
st[++top] = -2;
}
else if(str[i] == '['){
st[++top] = -3;
}
else{
if(str[i] == ')') tmp = -2;
else tmp = -3;
while(1){
if(top == -1){
printf("0\n");
return 0;
}
if(st[top] > 0){
tmp_ret+= st[top];
}
else if(st[top] == tmp){
if(tmp_ret == 0) st[top] = -tmp;
else{
st[top] = tmp_ret* (-tmp);
}
tmp_ret = 0;
break;
}
else{
printf("0\n");
return 0;
}
--top;
}
}
if(top == 0 && st[top] > 0){
ret+=st[top--];
}
}
if(top ==-1)
printf("%d\n", ret);
else
printf("0\n");
}