2024-10-01 12:01:13 +00:00
|
|
|
#include <stdio.h>
|
2024-10-02 12:27:38 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define LINESIZE 100
|
2024-10-02 12:33:13 +00:00
|
|
|
#define MENU_SIZE 100
|
2024-10-02 12:27:38 +00:00
|
|
|
|
2024-10-02 12:33:13 +00:00
|
|
|
struct pizza {
|
2024-10-02 12:27:38 +00:00
|
|
|
char name[LINESIZE];
|
|
|
|
float price;
|
2024-10-02 12:33:13 +00:00
|
|
|
};
|
2024-10-02 12:27:38 +00:00
|
|
|
|
2024-10-02 12:33:13 +00:00
|
|
|
char hacker_script(char l) {
|
|
|
|
switch (tolower(l)) {
|
2024-10-02 12:27:38 +00:00
|
|
|
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 'b': return '6';
|
|
|
|
case 't': return '7';
|
|
|
|
case 'q': return '9';
|
2024-10-02 12:33:13 +00:00
|
|
|
default: return tolower(l);
|
2024-10-02 12:27:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void transform_to_hacker_script(const char *src, char *dest) {
|
|
|
|
while (*src) {
|
|
|
|
*dest++ = hacker_script(*src++);
|
|
|
|
}
|
|
|
|
*dest = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
int contains_normalized(const char *name, const char *search) {
|
|
|
|
char transformed_name[LINESIZE], transformed_search[LINESIZE];
|
2024-10-02 12:28:51 +00:00
|
|
|
|
2024-10-02 12:27:38 +00:00
|
|
|
transform_to_hacker_script(name, transformed_name);
|
|
|
|
transform_to_hacker_script(search, transformed_search);
|
|
|
|
|
|
|
|
return strstr(transformed_name, transformed_search) != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int read_pizza(struct pizza *item) {
|
|
|
|
char line[LINESIZE];
|
|
|
|
|
|
|
|
if (!fgets(item->name, LINESIZE, stdin)) {
|
2024-10-02 12:28:51 +00:00
|
|
|
return 0;
|
2024-10-02 12:27:38 +00:00
|
|
|
}
|
|
|
|
item->name[strcspn(item->name, "\n")] = '\0';
|
|
|
|
|
|
|
|
if (!fgets(line, LINESIZE, stdin)) {
|
2024-10-02 12:28:51 +00:00
|
|
|
return 0;
|
2024-10-02 12:27:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
item->price = strtof(line, NULL);
|
2024-10-02 12:28:51 +00:00
|
|
|
return 1;
|
2024-10-02 12:27:38 +00:00
|
|
|
}
|
|
|
|
|
2024-10-01 12:01:13 +00:00
|
|
|
int main() {
|
2024-10-02 12:27:38 +00:00
|
|
|
struct pizza menu[MENU_SIZE];
|
|
|
|
char search[LINESIZE];
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
printf("Zadaj hladanu surovinu:\n");
|
|
|
|
fgets(search, LINESIZE, stdin);
|
2024-10-02 12:33:13 +00:00
|
|
|
search[strcspn(search, "\n")] = '\0';
|
2024-10-02 12:27:38 +00:00
|
|
|
|
|
|
|
printf("Zadaj jedalny listok:\n");
|
|
|
|
while (read_pizza(&menu[count])) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\nVysledky vyhladavania:\n");
|
|
|
|
int found_count = 0;
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
if (contains_normalized(menu[i].name, search)) {
|
|
|
|
printf("%s\n%.2f\n", menu[i].name, menu[i].price);
|
|
|
|
found_count++;
|
|
|
|
}
|
|
|
|
}
|
2024-10-02 12:33:13 +00:00
|
|
|
|
|
|
|
printf("Nacitanych %d poloziek.\n", count);
|
2024-10-02 12:27:38 +00:00
|
|
|
|
2024-10-01 12:01:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|