#include #include #include #include #define LINESIZE 100 #define MAX_ITEMS 100 struct pizza { float prize; char name[LINESIZE]; }; char hacker_script(char c) { if (isupper(c)) { return tolower(c); } char numbers[] = "0123456789"; char letters[] = "oizeasbtbq"; for (int i = 0; i < 10; i++) { if (c == numbers[i]) { return letters[i]; } } return c; } int search_string(const char* heap, const char* needle) { int heap_len = strlen(heap); int needle_len = strlen(needle); if (needle_len > heap_len) { return -1; } for (int i = 0; i <= heap_len - needle_len; i++) { int found = 1; for (int j = 0; j < needle_len; j++) { char h_char = hacker_script(heap[i + j]); char n_char = hacker_script(needle[j]); if (h_char != n_char) { found = 0; break; } } if (found) { return i; } } return -1; } int read_pizza(struct pizza* item, FILE* stream) { char line[LINESIZE]; char price_line[LINESIZE]; if (fgets(line, LINESIZE, stream) == NULL) { return 0; } line[strcspn(line, "\n")] = 0; if (fgets(price_line, LINESIZE, stream) == NULL) { return 0; } char* endptr; float value = strtof(price_line, &endptr); if (endptr == price_line || value == 0.0f) { return 0; } strcpy(item->name, line); item->prize = value; return 1; } int main() { char search_term[LINESIZE]; struct pizza items[MAX_ITEMS]; int item_count = 0; printf("Zadaj hladanu surovinu:\n"); if (fgets(search_term, LINESIZE, stdin) == NULL) { printf("Chyba pri čítaní hľadaného reťazca\n"); return 1; } search_term[strcspn(search_term, "\n")] = 0; printf("Zadaj jedalny listok:\n"); while (item_count < MAX_ITEMS && read_pizza(&items[item_count], stdin)) { item_count++; } for (int i = 0; i < item_count; i++) { if (search_string(items[i].name, search_term) != -1) { printf("%s\n", items[i].name); printf("%.2f\n", items[i].prize); } } printf("Nacitanych %d poloziek.\n", item_count); return 0; }