Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/evenFibonacci.c
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 за отступы и фигурные скобки у функций не по стайлгайду.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>

// рекурсивная функция просто считающая числа фиббоначи, принимает номер числа
// возвращает число фибоначчи
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
// рекурсивная функция просто считающая числа фиббоначи, принимает номер числа
// возвращает число фибоначчи
// рекурсивная функция просто считающая числа фибоначчи, принимает номер числа
// возвращает число фибоначчи

:)

int fibonacci(int n) {
if (n == 0 || n == 1) {
return n;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}

int main() {
int summ = 0;
// временная переменная, она будет содержать в себе числа фибоначчи
int tmp = 0;
Comment on lines +14 to +15
Copy link
Collaborator

Choose a reason for hiding this comment

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

Временные переменные лучше создать в месте использование. В данном случае прямо внутри цикла было бы лучше.

// номер числа фибоначчи
// первый номер равен 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) {

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

summ += tmp;
}
number++;
tmp = fibonacci(number);
}
printf("%d\n", summ);
return 0;
}
46 changes: 46 additions & 0 deletions src/palindromTask.c
Copy link
Collaborator

Choose a reason for hiding this comment

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <stdbool.h>
#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.

Содержательно функция делает не то, что просили, она просто проверяет является ли строка палиндромом, не думая о пробелах.

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;
}
}
Comment on lines +6 to +17
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, который Вы ещё и забываете почистить после выполнения программы.

printf("Введите число символов, которое хотите ввести, завершите ввод нажав "
"enter\n");
printf("На след строке введите строку и завершите ввод enter\n");
int len = 0;
scanf("%d", &len);
getchar();
char *arrayWithString = malloc(len * sizeof(char));
// счетчик чтобы считать кол-во не пробелов
int counter = 0;
Comment on lines +29 to +30
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 и можно было бы не передавать его в функцию.

for (int i = 0; i < len; i++) {
char tmp = ' ';
scanf("%c", &tmp);
if (tmp != ' ') {
arrayWithString[counter] = tmp;
++counter;
}
Comment on lines +34 to +37
Copy link
Collaborator

Choose a reason for hiding this comment

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

И ещё вопрос: а пользователь должен вводить длину строки с пробелами или нет? Потому что сейчас у Вас кучу места в массиве остаётся неиспользованным.

}
if (palindrom(arrayWithString, counter)) {
printf("Строка является палиндромом\n");
} else {
printf("Строка не является палиндромом\n");

return 0;
}
}