From 2e0d7f7853cf72340a090e30f63415f3f252d9da Mon Sep 17 00:00:00 2001 From: Deinerovych Date: Fri, 8 Nov 2024 14:20:41 +0100 Subject: [PATCH] hz7 --- cv7/.program.c.swp | Bin 0 -> 12288 bytes cv7/program.c | 30 +++++++++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 cv7/.program.c.swp diff --git a/cv7/.program.c.swp b/cv7/.program.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..036648593c2a403246f948a7cd707514300e21f4 GIT binary patch literal 12288 zcmeI1y=xRf6u>7oq8KCEXtyegA8@(cog|(3g_>}9#$4L)_I8rn+mBghKlBdK&h9|` z3$j{SXd^a4wAdVqt!QZx^Do#~`DSvPjY2?+h=I58yPdCn@6B(fJF`50vu;e4Dh!`P z>SyEmSf65vRjF0)+WFA7@6cZIVB6VZ;=wTBcpL&$YU8bBay*b?NrG2u70aka2FSpU z7#M9fDDiUGC&5%z&|z65IrB(9zUBzEE%^&f(?;~ zmaRq=J??Vf_PZr^?OwoTq=pbPUgS}XjY!~6V)N44qt|S(9D#3vwES$vNV1hMiUY>Z z)XIhlok%2S8N1T%nmVNg5tz^e_1zzYzO~v1CrcC98hU;sg%N_`^Ilt6afchBA&Rvx zJj`FcP$>#HhxJ~@D5nWSG7c~1tLj3=gH)HRKAI7Z2=lpV zFkMHeUOh{3GT@1yy}`yHjRQw%(qU#HjBFKO3kV}AJk`^44UV!psv9cpdc_@AB-{^+ z04nh%34_$O^3-+dB%4Jwcq9jJ@xatfW9$Bk*j?!akts?UsdTMeXuZ5k9$J7 z1eco|Rc{^DpB3ST_f~B-U$5`=rto=vIpyes && node->no) || (node->yes && !node->no)) { - return 0; // Некорректное состояние: одна ветка отсутствует +int validate_tree_structure(char lines[][MAX_LINE_LENGTH], int line_count) { + int leaf_count = 0; + int question_count = 0; + + for (int i = 0; i < line_count; i++) { + if (lines[i][0] == '*') { + leaf_count++; + } else { + question_count++; + if (i + 2 >= line_count || lines[i + 1][0] == '*' && lines[i + 2][0] == '*') { + continue; + } else if (i + 2 < line_count && lines[i + 2][0] != '*') { + return 0; // Обнаружена некорректная структура (более двух ответов) + } + } } - if (!node->yes && !node->no) { - return 1; // Листовой узел - } - return is_valid_tree(node->yes) && is_valid_tree(node->no); + + return question_count >= leaf_count; } int count_products(Node *node) { @@ -112,7 +121,7 @@ int main() { line_count++; } - if (line_count == 0) { + if (line_count == 0 || !validate_tree_structure(lines, line_count)) { printf("Expert z bufetu to vie.\n"); printf("Chybna databaza\n"); return 0; @@ -121,10 +130,9 @@ int main() { int index = 0; Node *root = parse_knowledge_base(lines, &index, line_count); - if (!root || !is_valid_tree(root)) { + if (!root) { printf("Expert z bufetu to vie.\n"); printf("Chybna databaza\n"); - free_tree(root); return 0; }