-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBeautifulStringHackerrank.cpp
More file actions
80 lines (79 loc) · 1.75 KB
/
BeautifulStringHackerrank.cpp
File metadata and controls
80 lines (79 loc) · 1.75 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
/*https://www.hackerrank.com/challenges/separate-the-numbers/problem*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
/*
store number and increase */
int main()
{
freopen("in.txt","r",stdin);
freopen("out.txt" ,"w",stdout);
//freopen("err.txt" ,"w",stderr);
ll t,i,n,l,j,k;
cin>>t;
while(t--)
{
string s;
cin>>s;
l=s.length();
string res,tmp;
ll flg=0,ind;
for(i=0;i<(l/2);i++)
{
tmp=" ";
for(ll in=0;in<=i;in++)
{
//k=s[in]-'0';
//cout<<k<<" ";
//ob<<k;
//res=ob.str();
//j=res.length();
tmp+=s[in];
}
tmp.erase(tmp.begin());
//cout<<tmp<<"ji"<<" ";
stringstream pp(tmp);
int k=0;
pp>>k;
j=tmp.length();
//cout<<j<<" "<<tmp<<" "<<k<<" ";
//ostringstream ob;
string res=tmp,app;
while(j<l)
{
k++;
ostringstream ob;
ob<<k;
app=ob.str();
j+=app.length();
res+=app;
}
//cout<<res<<" ";
if(res.compare(s)==0)
{
flg=1;
ind=i;
break;
}
else
{
continue;
}
}
if(flg)
{
cout<<"YES"<<" ";
for(i=0;i<=ind;i++)
{
cout<<s[i];
}
cout<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
//cout<<t<<" "<<"hello"<<endl;
return 0;
}