-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodejam2(Java).java
More file actions
90 lines (87 loc) · 1.89 KB
/
Codejam2(Java).java
File metadata and controls
90 lines (87 loc) · 1.89 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import java.util.*;
import java.io.*;
public class cj2_2
{
public static int stringtonumber(char s)
{
int num=0;
for(int i=0;i<1;i++)
{
if(s=='0')
num=num*10+0;
else if(s=='1')
num=num*10+1;
else if(s=='2')
num=num*10+2;
else if(s=='3')
num=num*10+3;
else if(s=='4')
num=num*10+4;
else if(s=='5')
num=num*10+5;
else if(s=='6')
num=num*10+6;
else if(s=='7')
num=num*10+7;
else if(s=='8')
num=num*10+8;
else if(s=='9')
num=num*10+9;
}
return num;
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int cou=1;
while(t-- > 0)
{
String s = sc.next();
char a[] = s.toCharArray();
int num1=0,num2=0;
String ans="";
for(int j=0;j<a.length;j++)
{
num1=stringtonumber(a[j]);
if(j == 0)
{
if(num1 > 0)
{
for(int i=1;i<=num1;i++)
ans += '(';
}
}
else if(j>=1)
{
if(num1>=num2)
{
for(int k=0;k<(num1-num2);k++)
{
ans += '(';
}
}
else
{
for(int k=0;k<(num2-num1);k++)
{
ans +=')';
}
}
}
else
{
for(int w=0;w<num1;w++)
ans += '(';
}
ans += a[j];
num2=num1;
}
num1=stringtonumber(a[a.length-1]);
for(int j=0;j<num1;j++)
ans += ')';
System.out.println("Case #" + (cou) + ": " + ans);
cou++;
}
}
}