Skip to content

Контрольная работа № 1 (142). Разгуляева А.И.#4

Open
ada1ra wants to merge 2 commits intomainfrom
kr_1
Open

Контрольная работа № 1 (142). Разгуляева А.И.#4
ada1ra wants to merge 2 commits intomainfrom
kr_1

Conversation

@ada1ra
Copy link
Owner

@ada1ra ada1ra commented Oct 17, 2025

No description provided.

@ada1ra ada1ra requested a review from chernishev October 17, 2025 14:20
Copy link
Collaborator

@p-senichenkov p-senichenkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сумма цифр: 6/10 (работает только в очень простом случае + мелкие недочёты)
Палиндром: 5/10 (работает неверно)

int maxSum = 0;
int maxSumInd[6] = {0};
for (int i = 0; i < sizeNumbers; i++) {
int sum = (numbers[i] / 10) + (numbers[i] - ((numbers[i] / 10) * 10));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А что если в массиве есть трёхзначные числа?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И ещё: для второй части этого выражения есть отдельный оператор. Подумайте, какая это арифметическая операция.

Comment on lines +19 to +21
for (int j = 0; j < sizeNumbers ;j++)
maxSumInd[j] = 0;
maxSumInd[i] = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот в этом месте получается квадратичная сложность. А можно минимальными изменениями добиться линейной.

Comment on lines +9 to +15
if (num % 2 == 1) {
num = num / 2;
binNum[count] = 1;
} else {
num = num / 2;
binNum[count] = 0;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это можно записать в две строчки.

}

//printf("%d", binNum[count]);
count = count + 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
count = count + 1;
++count;

}

for (int i = 0; i <= count; i++) {
if (binNum[i] == binNum[count - i])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь напутаны индексы, так что программа работает неверно. Более того, здесь гарантированно происходит обращение за границами массива.

for (int i = 1; i <= n; i++) {
int result = isPal(i);
if (result == 1)
printf("%d\n", i);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я это запустил, и оно не выводит и половины всех палиндромов.

Например, для 15 выводится 1 5, хотя там ещё есть 3, 7, 9 и 15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants