-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSeparateTheNumbers.cpp
71 lines (58 loc) · 1.29 KB
/
SeparateTheNumbers.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
#include <bits/stdc++.h>
using namespace std;
string get(string s, int start, int end){
string ans = "";
if(s[start] == '0'){
return "-1";
}
for(int i = start; i <= end; i++){
ans = ans + s[i];
}
return ans;
}
bool check(string s, int start, int end, string fnum){
string toCheck = "";
for(int i = start; i < end; i++){
toCheck += s[i];
if(toCheck[0] == '0'){
return false;
}
if(stoll(toCheck) == (stoll(fnum) + 1)){
fnum = toCheck;
toCheck = "";
if(i == end-1){
return true;
}
}
else if(stoll(toCheck) > (stoll(fnum) + 1)){
return false;
}
}
return false;
}
string check(string s){
int i = 0, n = s.size();
string ans = "NO";
while(i < n/2){
string fnum = get(s, 0, i);
if(fnum != "-1"){
if(check(s, i+1, n, fnum)){
ans = "YES " + fnum;
return ans;
}
}
i++;
}
return ans;
}
int main(){
int q;
cin >> q;
for(int a0 = 0; a0 < q; a0++){
string s;
cin >> s;
// your code goes here
cout << check(s) << endl;
}
return 0;
}