Skip to content

Comments

Контрольная работа №1. Кальсина Яна. Б43#6

Open
yaprogrammer18-yanchi wants to merge 1 commit intomainfrom
progress_check1_branch
Open

Контрольная работа №1. Кальсина Яна. Б43#6
yaprogrammer18-yanchi wants to merge 1 commit intomainfrom
progress_check1_branch

Conversation

@yaprogrammer18-yanchi
Copy link
Owner

Добавила решения первой и второй задачи из первой контрольной работы.

Copy link
Collaborator

@WoWaster WoWaster left a comment

Choose a reason for hiding this comment

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

+1 балл за дедлайн пойдёт в фибоначчи. Но в целом.
Настройте, пожалуйста, форматер и форматирование по Ctrl+S.

Comment on lines +14 to +15
// временная переменная, она будет содержать в себе числа фибоначчи
int tmp = 0;
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 +3 to +4
// рекурсивная функция просто считающая числа фиббоначи, принимает номер числа
// возвращает число фибоначчи
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
// рекурсивная функция просто считающая числа фиббоначи, принимает номер числа
// возвращает число фибоначчи
// рекурсивная функция просто считающая числа фибоначчи, принимает номер числа
// возвращает число фибоначчи

:)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Зачтено. 9 баллов. -1 за отступы и фигурные скобки у функций не по стайлгайду.

// первый номер равен 0, так что его можно не считать отдельно
int number = 1;
while (tmp <= 1000000) {
if ((tmp % 2) == 0) {
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
if ((tmp % 2) == 0) {
if (tmp % 2 == 0) {

Так тоже можно

#include <stdio.h>
#include <stdlib.h>

bool palindrom(char *line, int counter) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

По стайлгайду и вообще с точки зрения грамотного английского --- isPalindrome(char *str, int len)

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 +6 to +17
if ((counter % 2) == 0) {
for (int i = 0; i < (counter / 2); i++)
if (line[i] != line[counter - i - 1]) {
return false;
}
} else {
for (int i = 0; i < (counter / 2); i++)
if (line[i] != line[counter - i - 1]) {
printf("%c %c\n", line[i], line[counter - i - 1]);
return false;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

В теле if и else абсолютно одинаковый код по модулю printf во втором случае. Не надо так.

return true;
}

int main() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Вот здесь Вы попали в ловушку, потому что не следовали правилу "ввод-вывод отдельно, логика отдельно". Вы пытаетесь очистить строку от пробелов при вводе. Однако в итоге у Вас получается не C-string (нет '\0' в конце), а просто массив из char, который Вы ещё и забываете почистить после выполнения программы.

Comment on lines +29 to +30
// счетчик чтобы считать кол-во не пробелов
int counter = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Если бы Вы сделали правильный C-string, то на ней бы работал strlen и можно было бы не передавать его в функцию.

Comment on lines +34 to +37
if (tmp != ' ') {
arrayWithString[counter] = tmp;
++counter;
}
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.

Я сломался считать косяки в этой задачке. Так что пусть будет 4 балла и всё.

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