-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathANARCO9A_re.cpp
More file actions
37 lines (36 loc) · 1.11 KB
/
Copy pathANARCO9A_re.cpp
File metadata and controls
37 lines (36 loc) · 1.11 KB
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
#include<stdio.h>
#include<cstring>
using namespace std;
int main(){
char str[20020],stack[20020];
int t=1,top;
while(1){
int cntr=0;
top=0;
scanf("%s",&str);
if(str[0]=='-')break;
int len=strlen(str);
for(int i=0;i<len;i++){
if(top==0){stack[top]=str[i];top++;}
else if(str[i]=='{'){
stack[top]='{';
top++;
}
else if(str[i]=='}'){
if(stack[top-1]=='{')top--;
else {
stack[top]='}';
top++;
}
}
}
//if(top>0)
for(int i=0;i<top/2;i++){
if((stack[i]=='}'&&stack[top-1-i]=='{')){cntr+=2;}
else cntr++;
}
printf("%d. %d\n",t,cntr);
t++;
}
return 0;
}