-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoogle Qualification Round Problem B
More file actions
95 lines (80 loc) · 2.11 KB
/
Google Qualification Round Problem B
File metadata and controls
95 lines (80 loc) · 2.11 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
91
92
93
94
95
#include <bits/stdc++.h>
using namespace std;
string getString(char x)
{
string s(1, x);
return s;
}
string givesParentesis(char a ,char b)
{
string res = "";
int x = a - '0';
int y = b - '0';
if(a>b)
{
int tmp = (x-y);
while(tmp--)
{
res = res + ")";
}
}
else
{
int tmp = (y-x);
while(tmp--)
{
res = res + "(";
}
}
return res;
}
int main()
{
int tc;
int z = 1;
cin>>tc;
while(tc--)
{
string st;
cin>>st;
string sttmp = "";
string update = "";
for(int i=0 ; i<st.size()-1;i++)
{
sttmp = getString(st[i])+givesParentesis(st[i],st[i+1]) ;
update = update+sttmp;
}
update = update + getString(st[st.size()-1]);
// cout<<endl<<"final update "<<update<<endl;
//cout<<update<<" + \\\\\\\\\\\\\\\\\\\\/"<<endl;
/// Work For 1st Parenthesis
string blank = "";
//string s1;
int k = st[0]-'0';
while(k--)
{
blank = blank + "(";
}
sttmp = blank + update;
// cout<<sttmp<<" 1st "<<endl;
/////////////////////////////////
/// Work For last Parenthesis
k = st[st.size()-1]-'0';
blank = "";
while(k--)
{
blank = blank + ")";
}
sttmp = sttmp + blank ;
cout<<"Case #"<<z++<<": "<<sttmp<<endl;
}
}
// cout<<" getString(st[i]) "<<getString(st[i])<<endl;
// cout<<" givesParentesis(st[i],st[i+1]) "<<givesParentesis(st[i],st[i+1])<<endl;
// cout<<" st.substr(i+1,st.size()-1) "<<st.substr(i+1,st.size()-1)<<endl<<endl;
/*if(st[i]>st[i+1])*/
//else sttmp = ""+st.substr(i,i)+givesParentesis(st[i],st[i+1])+st.substr(i+1,st.size()-1);
/*getString(st[i+1])*/
//sttmp = ""+getString(st[i])+givesParentesis(st[i],st[i+1])+st.substr(i+1,st.size()-1);
// cout<<sttmp<<"last"<<endl;
//////////////////////////////////