File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,4 +16,9 @@ int main() {
1616 " %llu -> bin: %s\n Max length: %d\n " ,
1717 N, dtoab (N), count_max_ones (N)
1818 );
19+
20+ printf (
21+ " Series with length > 2: %d\n " ,
22+ count_ones_series (N)
23+ );
1924}
Original file line number Diff line number Diff line change @@ -50,4 +50,22 @@ int count_max_ones(unsigned long long N) {
5050 max = current > max ? current : max;
5151 }
5252 return max;
53+ }
54+
55+ // нахождение количества серий
56+ // из единиц длинной больше 2
57+ int count_ones_series (unsigned long long N) {
58+ char *str = dtoab (N);
59+ int count = 0 , current = 0 ;
60+
61+ for (int i = 0 ; str[i] != 0 ; i++) {
62+ if (str[i] == ' 1' ) {
63+ current++;
64+ } else {
65+ if (current > 2 ) count++;
66+ current = 0 ;
67+ }
68+ }
69+ if (current > 2 ) count++;
70+ return count;
5371}
Original file line number Diff line number Diff line change @@ -11,4 +11,8 @@ char *dtoab(unsigned long long N);
1111
1212// нахождение длины максимальной
1313// последовательности из единиц
14- int count_max_ones (unsigned long long N );
14+ int count_max_ones (unsigned long long N );
15+
16+ // нахождение количества серий
17+ // из единиц длинной больше 2
18+ int count_ones_series (unsigned long long N );
You can’t perform that action at this time.
0 commit comments