-
Notifications
You must be signed in to change notification settings - Fork 0
/
anarc09b.cpp
41 lines (39 loc) · 868 Bytes
/
anarc09b.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
#include<cstdio>
#include<cstring>
#include<stack>
using namespace std;
int computeMinCost(char *str);
int computeMinCost(char* str, int lIndex, int rIndex, int** array);
int main() {
char str[2050];
int test = 0;
while(true) {
++test;
scanf("%s", str);
if(str[0] == '-') {
break;
}
int len = strlen(str);
int cost = computeMinCost(str);
printf("%d. %d\n", test, cost);
}
return 0;
}
int computeMinCost(char *str) {
stack<char> stk;
int cost = 0;
for(int i=0;i<strlen(str);++i) {
char c=str[i];
if(c == '{') {
stk.push('{');
} else {
if(stk.empty()) {
stk.push('{');
cost++;
} else {
stk.pop();
}
}
}
return cost + stk.size()/2;
}