2024-10-03 21:16:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2024-10-04 12:52:13 +00:00
|
|
|
#include <stdlib.h>
|
2024-10-03 21:16:54 +00:00
|
|
|
#include <ctype.h>
|
2024-10-03 21:02:43 +00:00
|
|
|
|
2024-10-04 12:52:13 +00:00
|
|
|
#define BUFFER_SIZE 100
|
2024-10-04 12:59:12 +00:00
|
|
|
#define MAX_ITEMS 100
|
2024-10-04 12:52:13 +00:00
|
|
|
|
2024-10-04 12:59:12 +00:00
|
|
|
struct FoodItem {
|
|
|
|
float price;
|
2024-10-04 12:52:13 +00:00
|
|
|
char name[BUFFER_SIZE];
|
|
|
|
};
|
|
|
|
|
2024-10-04 12:59:12 +00:00
|
|
|
// Převod znaku na Leetspeak
|
2024-10-04 12:52:13 +00:00
|
|
|
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);
|
|
|
|
}
|
2024-10-04 12:50:33 +00:00
|
|
|
}
|
|
|
|
|
2024-10-04 12:59:12 +00:00
|
|
|
// Převod řetězce na Leetspeak
|
2024-10-04 12:52:13 +00:00
|
|
|
void apply_leetspeak(char *input) {
|
|
|
|
for (int i = 0; input[i] != '\0'; i++) {
|
|
|
|
input[i] = to_leetspeak(input[i]);
|
2024-10-03 21:16:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-04 12:59:12 +00:00
|
|
|
// Kontrola existence podřetězce ve jménu
|
|
|
|
int contains_substring(const char *item_name, const char *keyword) {
|
2024-10-04 12:52:13 +00:00
|
|
|
char modified_name[BUFFER_SIZE];
|
|
|
|
char modified_keyword[BUFFER_SIZE];
|
2024-10-03 21:16:54 +00:00
|
|
|
|
2024-10-04 12:59:12 +00:00
|
|
|
strncpy(modified_name, item_name, BUFFER_SIZE);
|
2024-10-04 12:52:13 +00:00
|
|
|
strncpy(modified_keyword, keyword, BUFFER_SIZE);
|
2024-10-03 21:16:54 +00:00
|
|
|
|
2024-10-04 12:52:13 +00:00
|
|
|
apply_leetspeak(modified_name);
|
|
|
|
apply_leetspeak(modified_keyword);
|
2024-10-04 12:50:33 +00:00
|
|
|
|
2024-10-04 12:52:13 +00:00
|
|
|
return strstr(modified_name, modified_keyword) != NULL;
|
|
|
|
}
|
2024-10-04 12:50:33 +00:00
|
|
|
|
2024-10-04 12:59:12 +00:00
|
|
|
// Funkce pro načtení položky
|
|
|
|
int load_food_item(struct FoodItem* item) {
|
2024-10-04 12:52:13 +00:00
|
|
|
char temp_price[BUFFER_SIZE];
|
2024-10-04 12:20:12 +00:00
|
|
|
|
2024-10-04 12:59:12 +00:00
|
|
|
// Čtení názvu položky
|
|
|
|
if (!fgets(item->name, BUFFER_SIZE, stdin)) {
|
|
|
|
return 0; // Chyba při čtení nebo konec vstupu
|
2024-10-04 12:52:13 +00:00
|
|
|
}
|
|
|
|
|
2024-10-04 12:59:12 +00:00
|
|
|
// Odstranění znaku nového řádku
|
|
|
|
item->name[strcspn(item->name, "\n")] = '\0';
|
2024-10-04 12:50:33 +00:00
|
|
|
|
2024-10-04 12:59:12 +00:00
|
|
|
// Čtení ceny položky
|
2024-10-04 12:52:13 +00:00
|
|
|
if (!fgets(temp_price, BUFFER_SIZE, stdin)) {
|
2024-10-04 12:59:12 +00:00
|
|
|
return 0; // Chyba při čtení nebo konec vstupu
|
2024-10-04 12:52:13 +00:00
|
|
|
}
|
|
|
|
|
2024-10-04 12:59:12 +00:00
|
|
|
// 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;
|
2024-10-04 12:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2024-10-04 12:59:12 +00:00
|
|
|
char search_keyword[BUFFER_SIZE];
|
|
|
|
struct FoodItem menu_items[MAX_ITEMS];
|
|
|
|
int item_count = 0;
|
2024-10-04 12:52:13 +00:00
|
|
|
|
2024-10-04 12:59:12 +00:00
|
|
|
// Vstup hledaného klíčového slova
|
2024-10-04 12:52:13 +00:00
|
|
|
printf("Zadaj hladanu surovinu:\n");
|
2024-10-04 12:59:12 +00:00
|
|
|
fgets(search_keyword, BUFFER_SIZE, stdin);
|
|
|
|
search_keyword[strcspn(search_keyword, "\n")] = '\0'; // Odstranění znaku nového řádku
|
2024-10-04 12:52:13 +00:00
|
|
|
|
2024-10-04 12:59:12 +00:00
|
|
|
// Vstup dat o položkách
|
2024-10-04 12:52:13 +00:00
|
|
|
printf("Zadaj jedalny listok:\n");
|
2024-10-04 12:59:12 +00:00
|
|
|
while (item_count < MAX_ITEMS && load_food_item(&menu_items[item_count])) {
|
|
|
|
item_count++;
|
2024-10-04 12:52:13 +00:00
|
|
|
}
|
2024-10-04 12:50:33 +00:00
|
|
|
|
2024-10-04 12:52:13 +00:00
|
|
|
int match_count = 0;
|
2024-10-04 12:02:06 +00:00
|
|
|
|
2024-10-04 12:59:12 +00:00
|
|
|
// 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);
|
2024-10-04 12:52:13 +00:00
|
|
|
match_count++;
|
2024-10-03 21:16:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-04 12:59:12 +00:00
|
|
|
// Výstup celkového počtu načtených položek
|
|
|
|
printf("Nacitanych %d poloziek.\n", item_count);
|
2024-10-04 12:50:33 +00:00
|
|
|
|
2024-10-03 21:25:32 +00:00
|
|
|
return 0;
|
2024-10-03 21:18:50 +00:00
|
|
|
}
|