Skip to content

Comments

Until 30 09#2

Open
Andrew-Kochanov wants to merge 21 commits intomainfrom
until_30_09
Open

Until 30 09#2
Andrew-Kochanov wants to merge 21 commits intomainfrom
until_30_09

Conversation

@Andrew-Kochanov
Copy link
Owner

Дз до 30.09

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.

Настройте, пожалуйста, форматер. Ну вот у if'ов точно скобочки не там, где нужно стоят.

balance_stap.c Outdated
// коэф для проверки вложености скобок во время пробежки по строке(если коэф меньше 0, вложенность нарушена)
// открывающая скобка имеет коэф +1
// закрывающая скобка имеет коэф -1
int ratio = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ну и ratio это традиционно "отношение" в смысле дробей (7/9 например), здесь скорее счётчик

count_zero.c Outdated

for (int i = 0; i < len; i++)
{
array[i] = rand() % 10;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Если уж вызываете rand, то не забывайте его инициализировать. А то вдруг ваш код работает только на одном входе.

occur_str.c Outdated
#include <stdlib.h>

// функция для создания подстроки из строки по индексам
char* cross(char* str, int indStart, int indFinish){
Copy link
Collaborator

Choose a reason for hiding this comment

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

Название вообще не несёт смысла.

occur_str.c Outdated
// длина подстроки с учетом нулевого элемента
int len = indFinish - indStart + 1;
// выделение памяти
char *crossStr = (char *)malloc((len) * sizeof(char));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Поиск подстроки и так не дешевая операция. Зачем ещё и дополнительную память выделять?

occur_str.c Outdated
Comment on lines 44 to 53
for(int i = 0; i < lenStr - lenStr1 + 1; i++)
{
char* str2 = cross(str, i, i + lenStr1);
if (strcmp(str1, str2) == 0)
{
count++;
}
// освобождаем память
free(str2);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Можно СИИИИЛЬНО проще, особенно, если Вы уже знаете (судя по strcspn() выше) про string.h, хотя можно и без него. Но точно можно без выделения памяти.

@WoWaster
Copy link
Collaborator

WoWaster commented Oct 8, 2025

Кстати, раз уж у Вас тут оказались файлы из другой ветки, то скорее всего, при вливании, Вы и из main потрёте все файлы :(

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.

И жмите Resolve conversation там, где исправили.

balance_stap.c Outdated
}

// если после пробежки по строке коэф неравен 0, значит, количество открывающих и закрывающих скобок разное
if (count == 0 && flag) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Правда ли в этом месте программы flag == (count == 0)? Да! Вам не нужен flag! Избавьтесь от него

balance_stap.c Outdated
char str[1000];
printf("Введите строку: ");
fgets(str, sizeof(str), stdin);
balance(str);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ну, почти. Пусть balance возвращает bool, а Вы уже в main смотрите, что пришло и печатайте.

balance_stap.c Outdated
count++;

} else if (str[i] == ')') {
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 -= 1;
count--;

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.

Зачтено.

WoWaster
WoWaster previously approved these changes Dec 20, 2025
Comment on lines 21 to 25
if (count == 0) {
return true;
} else {
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.

Suggested change
if (count == 0) {
return true;
} else {
return false;
}
return count == 0;

Вообще экивалентно этому. Запомните и не пишите так больше.

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