-
Notifications
You must be signed in to change notification settings - Fork 5
/
Separate-The-Numbers.cpp
97 lines (94 loc) · 2.11 KB
/
Separate-The-Numbers.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
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
void check(string str)
{
int len = str.size() / 2 , a;
string copy;
string temp1 = "";
string temp2 = "";
int ln = 1, l = ln;
while(ln <= len+1)
{
int i = 0 , flag = 0;
int nine_flag = 1;
while(i < str.size())
{
temp1 = "";
temp2 = "";
l = ln;
while(l)
{
temp1 = temp1 + str[i];
l--;
if(str[i] != '9')
nine_flag = 0;
i++;
}
if(i == 0+ln)
{
copy = temp1;
}
if(temp1[0] == '0')
{
flag = 1;
break;
}
if(nine_flag == 1 && str[i] == '1')
{
ln++;
l = ln;
}
else if(nine_flag == 1 && str[i] != '1')
{
l = ln+1;
}
else
l = ln;
nine_flag = 1;
int save = i;
while(l)
{
temp2 = temp2 + str[i];
l--;
if(str[i] != '9')
nine_flag = 0;
i++;
}
if(temp2[0] == '0')
{
flag = 1;
break;
}
if(i < str.size())
i = save;
if(atoi(temp2.c_str()) - atoi(temp1.c_str()) != 1)
{
flag = 1;
break;
}
if(nine_flag == 1)
l = ln + 1;
else
l = ln;
}
ln++;
if(flag == 0)
{
cout << "YES " << copy <<endl;
return ;
}
}
cout << "NO" << endl;
}
int main(){
int q;
cin >> q;
for(int i = 0; i < q; i++)
{
string str;
cin >> str;
check(str);
}
return 0;
}