-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVec.java
More file actions
88 lines (86 loc) · 1.81 KB
/
Vec.java
File metadata and controls
88 lines (86 loc) · 1.81 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
import java.io.*;
import java.util.*;
class Vec
{
static String printColX(int col, String tree)
{
char temp[]=tree.toCharArray();
String res="";
int sz=tree.length();
String arr[][]=new String[2][sz];
//try{
arr[0][0]=Character.toString(temp[0]);
arr[1][0]="0";
int count=0;
String prev="";
for(int i=1;i<tree.length();i++)
{
String t=Character.toString(temp[i]);
if(t.equals("("))
{
count++;
arr[0][i]=Character.toString(temp[i]);
arr[1][i]=Integer.toString(1000);
}
else if(t.equals("."))
{
if(prev.equals("."))
{
prev=t;
continue;
}
count--;
arr[0][i]=Character.toString(temp[i]);
arr[1][i]=Integer.toString(1000);
}
else if(t.equals(")"))
{
count--;
arr[0][i]=Character.toString(temp[i]);
arr[1][i]=Integer.toString(1000);
}
else
{
arr[0][i]=Character.toString(temp[i]);
arr[1][i]=Integer.toString(count);
}
prev=t;
}
for(int i=0;i<sz;i++)
{
System.out.println(arr[1][i]);
int comp=Integer.parseInt(arr[1][i]);
if(comp==col)
{
res=res+arr[0][i];
}
}
if(res.equals(""))
{
return "Hallelujah!";
}
return res;
//}
//catch(Exception e)
//{
// System.out.println(e);
//}
//return res;
}
public static void main(String arg[]) throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int testNo=Integer.parseInt(br.readLine());
String out[]=new String[testNo];
for(int i=0;i<testNo;i++)
{
int col=Integer.parseInt(br.readLine());
String iTree=br.readLine();
out[i]=printColX(col,iTree);
}
for(int i=0;i<testNo;i++)
{
System.out.println(out[i]);
}
}
}