-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNesting Depth.cpp
More file actions
46 lines (40 loc) · 895 Bytes
/
Nesting Depth.cpp
File metadata and controls
46 lines (40 loc) · 895 Bytes
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
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t; cin>>t;
for(int tc=1; tc<=t; tc++)
{
cout<<"Case #"<<tc<<": ";
int depth = 0;
string s; cin>>s;
for(int i=0; i<s.size(); i++)
{
if( (s[i]-48) > depth )
{
for(int j=1; j <= (s[i]-48)-depth; j++)
{
cout<<"(";
}
depth = s[i]-48;
}
else
{
for(int j=1; j <= depth-(s[i]-48); j++)
{
cout<<")";
}
depth = s[i]-48;
}
cout<<s[i];
}
for(int i=0; i<depth; i++)
{
cout<<")";
}
cout<<"\n";
}
}