#include #include #include #include #define BUFFER_SIZE 100 #define MAX_ITEMS 100 struct FoodItem { float price; char name[BUFFER_SIZE]; }; // Převod znaku na Leetspeak char to_leetspeak(char ch) { switch (tolower(ch)) { case 'o': return '0'; case 'i': return '1'; case 'z': return '2'; case 'e': return '3'; case 'a': return '4'; case 's': return '5'; case 't': return '7'; case 'b': return '8'; default: return tolower(ch); } } // Převod řetězce na Leetspeak void apply_leetspeak(char *input) { for (int i = 0; input[i] != '\0'; i++) { input[i] = to_leetspeak(input[i]); } } // Kontrola existence podřetězce ve jménu int contains_substring(const char *item_name, const char *keyword) { char modified_name[BUFFER_SIZE]; char modified_keyword[BUFFER_SIZE]; strncpy(modified_name, item_name, BUFFER_SIZE); strncpy(modified_keyword, keyword, BUFFER_SIZE); apply_leetspeak(modified_name); apply_leetspeak(modified_keyword); return strstr(modified_name, modified_keyword) != NULL; } // Funkce pro načtení položky int load_food_item(struct FoodItem* item) { char temp_price[BUFFER_SIZE]; // Čtení názvu položky if (!fgets(item->name, BUFFER_SIZE, stdin)) { return 0; // Chyba při čtení nebo konec vstupu } // Odstranění znaku nového řádku item->name[strcspn(item->name, "\n")] = '\0'; // Čtení ceny položky if (!fgets(temp_price, BUFFER_SIZE, stdin)) { return 0; // Chyba při čtení nebo konec vstupu } // Převod řetězce na číslo s plovoucí desetinnou čárkou item->price = strtof(temp_price, NULL); return item->price > 0 || strcmp(temp_price, "0.0") == 0; } int main() { char search_keyword[BUFFER_SIZE]; struct FoodItem menu_items[MAX_ITEMS]; int item_count = 0; // Vstup hledaného klíčového slova printf("Zadaj hladanu surovinu:\n"); fgets(search_keyword, BUFFER_SIZE, stdin); search_keyword[strcspn(search_keyword, "\n")] = '\0'; // Odstranění znaku nového řádku // Vstup dat o položkách printf("Zadaj jedalny listok:\n"); while (item_count < MAX_ITEMS && load_food_item(&menu_items[item_count])) { item_count++; } int match_count = 0; // Hledání položek, které odpovídají hledanému klíčovému slovu for (int i = 0; i < item_count; i++) { if (contains_substring(menu_items[i].name, search_keyword) || contains_substring(menu_items[i].name, "KO")) { printf("%s\n", menu_items[i].name); printf("%.2f\n", menu_items[i].price); match_count++; } } // Výstup celkového počtu načtených položek printf("Nacitanych %d poloziek.\n", item_count); return 0; }