-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodejam2020p2.cpp
98 lines (94 loc) · 1.98 KB
/
codejam2020p2.cpp
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
96
97
98
#include <bits/stdc++.h>
#define fori(x,y) for(int i = x ; i < y ; i++)
#define forj(x,y) for(int j = x ; j < y ; j++)
using namespace std;
int mx=-99;
string fixS(string s, char num)
{
int help;
stringstream sss;
sss<<num;
sss>>help;
if(help>mx)
{
return s;
}
else
{
string ans="";
int ind=0,laux;
for(int l = 0 ; l < s.size(); l++)
{
if(s[l]=='(' or s[l]==')')
continue;
if(s[l]>num)
{
ind++;
if(ind==1)
laux=l;
}
else
{
if(ind!=0)
{
ans+="(";
ans+=fixS(s.substr(laux,ind),num+1);
ans+=")";
}
ind=0;
ans+=s[l];
}
//cout<<ans<<" iteracion ans"<<endl;
}
if(ind!=0)
{
ans+="(";
ans+=fixS(s.substr(laux,ind),num+1);
ans+=")";
}
//cout<<ans<< " la respuesta"<<endl;
return ans;
}
}
int main()
{
int t,ind=0;
string s,aux,aux1,aux2,res="";
cin>>t;
for(int p = 1; p <= t; p++)
{
cin>>s;
for(int i = 0 ; i<s.size();i++)
{
if(s[i]>mx)
mx=s[i];
}
char au=mx;
stringstream ss;
ss<<au;
ss>>mx;
fori(0,s.size())
{
if(s[i]=='0')
{
if(i!=ind)
{
res+="(";
res+=fixS("("+s.substr(ind,i-ind)+")",'1');
res+=")";
}
res+="0";
ind=i+1;
}
}
if(s.size()!=ind)
{
res+="(";
res+=fixS("("+s.substr(ind,s.size()-ind)+")",'1');
res+=")";
}
cout<<"Case #"<<p<<": "<<res<<endl;
res="";
ind=0;
}
}