forked from sunnysetia93/competitive-coding-problems
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSplitting a String Into Descending Consecutive Values.cpp
More file actions
116 lines (70 loc) · 2.56 KB
/
Splitting a String Into Descending Consecutive Values.cpp
File metadata and controls
116 lines (70 loc) · 2.56 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
class Solution {
public:
bool splitString(string s) {
int i=0;
while(s[i]){
if(s[i]=='0')
i++;
else{
break;
}
}
int size=s.size();
//cout<<"New :"<<s<<endl;
i=0;
while(i<(1<<size)){
bool space =false;
int number=i;
vector<bool>arr;
int times=0;
while(times<32){
arr.push_back((number&(1<<times))==0);
times++;
}
int j=0;
vector<long long>splittedNum;
while(j<32){
int k=j;
string childS;
while(k<32){
if(arr[j]==arr[k])k++;
else break;
}
if(j!=size){
childS=s.substr(j,k-j);
int ind=0;
string newChildS;
//cout<<"input :"<<childS<<"--";
int index=0;
for(auto ele:childS){
if(!(ele>='0'&&ele<='9')){
break;
}
index++;
}
childS=childS.substr(0,index);
splittedNum.push_back(stoll(childS,nullptr,10));
}
j=k;
}
int I=1;
bool flag=true;
//cout<<"\nhere :"<<splittedNum.size()<<endl;
reverse(splittedNum.begin(),splittedNum.end());
while(I<splittedNum.size()){
//cout<<splittedNum[I]<<" "<<splittedNum[I-1]<<"--";
if(splittedNum[I]-splittedNum[I-1]!=1)
{
flag=false;
break;
}
I++;
}
if(flag&&splittedNum.size()>1&&!space)
return true;
//cout<<endl;
i++;
}
return false;
}
};