- Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathNestingDepth.java
44 lines (37 loc) · 1.34 KB
/
NestingDepth.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
/*
Problem Link - https://codingcompetitions.withgoogle.com/codejam/round/000000000019fd27/0000000000209a9f
*/
importjava.util.*;
classSolution{
publicstaticvoidmain(Stringargs[]){
Scanners = newScanner(System.in);
intt = s.nextInt();
for(inti=0;i<t;i++){
Stringstr = s.next();
StringBuffersb = newStringBuffer("");
intpN = str.charAt(0) - '0';
for(intj=0;j<pN;j++) sb.append("(");
sb.append(str.charAt(0));
for(intj=1;j<str.length();j++){
intcN = str.charAt(j) - '0';
if(cN > pN){
for(intk=0;k<(cN-pN);k++){
sb.append("(");
}
sb.append(str.charAt(j));
}
elseif(cN < pN){
for(intk=0;k<(pN-cN);k++){
sb.append(")");
}
sb.append(str.charAt(j));
}
elseif(cN == 0 || pN == cN) sb.append(str.charAt(j));
pN = cN;
}
pN = str.charAt(str.length()-1) - '0';
for(intj=0;j<pN;j++) sb.append(")");
System.out.println("Case #"+(i+1)+": "+sb);
}
}
}