This commit is contained in:
Oleksandr Vyshniakov 2026-01-25 14:26:33 +01:00
parent ea7b709255
commit 29076c8d00
8 changed files with 9 additions and 9 deletions

Binary file not shown.

View File

@ -10,11 +10,11 @@ struct pizza {
}; };
int read_pizza_list(struct pizza* list) { int read_pizza_list(struct pizza* list) {
int counter = 0; int counter = 0; // считает, сколько пицц реально прочитано
char line[200]; char line[200]; // буфер для строк
for (int i=0; i < LIST_SIZE; i++) { for (int i=0; i < LIST_SIZE; i++) {
struct pizza item; struct pizza item;
memset(&item,0,sizeof(struct pizza)); memset(&item,0,sizeof(struct pizza)); //заполняем память нулями
if (fgets(line, sizeof(line), stdin)==NULL) { if (fgets(line, sizeof(line), stdin)==NULL) {
break; break;
} }

View File

@ -10,11 +10,11 @@ struct station* create_station() {
return s; return s;
} }
int select_track(struct station* s, const char* target) { int select_track(struct station* s, const char* target) { //в какой bucket положить строку.
unsigned long hash = 5381; //5381 это алгоритм DJB2 unsigned long hash = 5381; //5381 это алгоритм DJB2
int c; int c;
while ((c = *target++)) { // не забываем ++ чтобы идти по строке while ((c = *target++)) {
hash = ((hash << 5) + hash) + c; //hash << 5 сдвигает все биты числа hash на 5 позиций влево. Это тоже самое, что умножить на 2 в пятой степени hash = ((hash << 5) + hash) + c; //hash << 5 сдвигает все биты числа hash на 5 позиций влево. Это тоже самое, что умножить на 2 в пятой степени
} }
@ -53,7 +53,7 @@ void add_target_capacity(struct station* s, const char* target, int capacity) {
prev->next = new_car; prev->next = new_car;
} }
int get_target_capacity(struct station* s, const char* target) { int get_target_capacity(struct station* s, const char* target) { //ищет станцию и возвращает её capacity.
if (!s || !target) return 0; if (!s || !target) return 0;
int index = select_track(s, target); int index = select_track(s, target);

View File

@ -19,11 +19,11 @@ static TreeNode* read_tree_node() {
if (buffer[0] == '\n' || buffer[0] == '\r') if (buffer[0] == '\n' || buffer[0] == '\r')
return NULL; return NULL;
TreeNode *node = calloc(1, sizeof(TreeNode)); TreeNode *node = calloc(1, sizeof(TreeNode)); //Создаём новый узел дерева.
if (!node) if (!node)
exit(1); exit(1);
strncpy(node->text, buffer, MAXLINE - 1); strncpy(node->text, buffer, MAXLINE - 1); //M чтобы оставить место для \0
if (node->text[0] == '*') { if (node->text[0] == '*') {
node->yes_branch = NULL; node->yes_branch = NULL;
@ -43,7 +43,7 @@ static void free_tree(TreeNode *root) {
free(root); free(root);
} }
static int count_leafs(TreeNode *root) { static int count_leafs(TreeNode *root) { //количество ответов
if (!root) return 0; if (!root) return 0;
if (!root->yes_branch && !root->no_branch) if (!root->yes_branch && !root->no_branch)
return 1; return 1;

0
sk2/Makefile Normal file
View File

0
sk2/calculator.c Normal file
View File

0
sk2/calculator.h Normal file
View File

0
sk2/main.c Normal file
View File