-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNesting_Depth.java
45 lines (45 loc) · 1.26 KB
/
Nesting_Depth.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
import java.util.*;
public class Solution
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
for(int i=1;i<=t;i++)
{
String s=sc.next();
String s1="";
int count=0;
for(int j=0;j<s.length();j++)
{
int val=s.charAt(j)-48;
if(val==count)
s1+=s.charAt(j);
else if(val>count)
{
int temp=val-count;
for(int k=0;k<temp;k++)
{
s1 += '(';
count++;
}
s1+=s.charAt(j);
}
else
{
int temp=count-val;
for(int k=0;k<temp;k++)
{
s1 += ')';
count--;
}
s1+=s.charAt(j);
}
//System.out.println(s1+" "+count+" "+val);
}
while(count--!=0)
s1+=')';
System.out.println("Case #"+i+": "+s1);
}
}
}