-
Notifications
You must be signed in to change notification settings - Fork 0
/
Anarco.java
54 lines (51 loc) · 883 Bytes
/
Anarco.java
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
package ques;
import java.util.Scanner;
public class Anarco {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int k=1;
while(true){
String s=scanner.next();
char[] ch=s.toCharArray();
if(s.charAt(0)=='-')
break;
int l=s.length();
int[] dp=new int[l+1];
for(int i=0;i<l;i++){
if(ch[i]=='{')
dp[i]=1;
else
dp[i]=-1;
}
int count=0;
if(dp[0]==-1){
dp[0]=1;
ch[0]='{';
count++;
}
for(int i=1;i<l;i++){
dp[i]=dp[i-1]+dp[i];
if(dp[i]<0){
dp[i]=1;
ch[i]='{';
count++;
}
}
/*if(dp[l-1]>=1){
dp[l-1]=-1;
ch[0]='}';
count++;
}
for(int i=l-2;i>=0;i--){
//dp[i]=dp[i-1]+dp[i];
if(dp[i+1]+dp[i]>0){
dp[i]=-1;
ch[i]='}';
count++;
}
}*/
System.out.println(k+". "+(count+dp[l-1]/2));
k++;
}
}
}