Skip to content

Commit 6dd0650

Browse files
committed
minor comments formatting
1 parent 295a215 commit 6dd0650

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

Variants/Lab_9/var_11/main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// доп: вывести кол во серий из единиц длинной больше 2
66

77
#include "sequence.h"
8+
#define DOP
89

910
int main() {
1011
// вводим N
@@ -17,8 +18,12 @@ int main() {
1718
N, dtoab(N), count_max_ones(N)
1819
);
1920

20-
printf(
21+
#ifdef DOP
22+
23+
printf( // количество серий из единиц
2124
"Series with length > 2: %d\n",
2225
count_ones_series(N)
2326
);
27+
28+
#endif
2429
}

Variants/Lab_9/var_11/sequence.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ char *dtoab(unsigned long long N) {
3030
// сдвигаем чтобы получить следующий бит
3131
N = N >> 1;
3232
}
33-
3433
// добавляем в конец \0 и выходим
3534
arr[len] = 0;
3635
return arr;
@@ -55,17 +54,22 @@ int count_max_ones(unsigned long long N) {
5554
// нахождение количества серий
5655
// из единиц длинной больше 2
5756
int count_ones_series(unsigned long long N) {
57+
// преобразуем число в двоичную строку
5858
char *str = dtoab(N);
5959
int count = 0, current = 0;
6060

61+
// проходим по всем битам числа
6162
for (int i = 0; str[i] != 0; i++) {
6263
if (str[i] == '1') {
6364
current++;
6465
} else {
66+
// увеличиваем счетчик если последовательность > 2
6567
if (current > 2) count++;
68+
// обнуляем счетчик
6669
current = 0;
6770
}
6871
}
72+
// не забываем про младшие биты
6973
if (current > 2) count++;
7074
return count;
7175
}

0 commit comments

Comments
 (0)