2024-10-01 12:01:13 +00:00
|
|
|
#include <stdio.h>
|
2024-10-02 18:39:17 +00:00
|
|
|
#include <stdlib.h>
|
2024-10-02 18:26:34 +00:00
|
|
|
#include <ctype.h>
|
2024-10-02 18:39:17 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define LINESIZE 100
|
|
|
|
#define MENU_SIZE 100
|
2024-10-02 12:27:38 +00:00
|
|
|
|
2024-10-02 18:39:17 +00:00
|
|
|
struct pizza {
|
|
|
|
char name[LINESIZE];
|
|
|
|
float price;
|
2024-10-02 12:33:13 +00:00
|
|
|
};
|
2024-10-02 12:27:38 +00:00
|
|
|
|
2024-10-02 18:39:17 +00:00
|
|
|
char hacker_script(char l) {
|
2024-10-02 18:44:48 +00:00
|
|
|
switch (l) {
|
2024-10-02 19:00:52 +00:00
|
|
|
case '0': return 'o';
|
|
|
|
case '1': return 'i';
|
|
|
|
case '2': return 'z';
|
|
|
|
case '3': return 'e';
|
|
|
|
case '4': return 'a';
|
|
|
|
case '5': return 's';
|
|
|
|
case '6': return 'b';
|
|
|
|
case '7': return 't';
|
|
|
|
case '8': return 'b';
|
|
|
|
case '9': return 'q';
|
|
|
|
default: return l;
|
2024-10-02 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void transform_to_hacker_script(const char *src, char *dest) {
|
|
|
|
while (*src) {
|
2024-10-02 19:00:52 +00:00
|
|
|
*dest++ = hacker_script(*src++);
|
2024-10-02 18:39:17 +00:00
|
|
|
}
|
|
|
|
*dest = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
int contains_normalized(const char *name, const char *search) {
|
|
|
|
char transformed_name[LINESIZE], transformed_search[LINESIZE];
|
|
|
|
transform_to_hacker_script(name, transformed_name);
|
|
|
|
transform_to_hacker_script(search, transformed_search);
|
2024-10-02 19:04:28 +00:00
|
|
|
|
|
|
|
for (int i = 0; transformed_name[i]; i++) {
|
|
|
|
transformed_name[i] = tolower(transformed_name[i]);
|
|
|
|
}
|
|
|
|
for (int i = 0; transformed_search[i]; i++) {
|
|
|
|
transformed_search[i] = tolower(transformed_search[i]);
|
|
|
|
}
|
|
|
|
|
2024-10-02 18:39:17 +00:00
|
|
|
return strstr(transformed_name, transformed_search) != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int read_pizza(struct pizza *item) {
|
|
|
|
char line[LINESIZE];
|
|
|
|
if (!fgets(item->name, LINESIZE, stdin)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
item->name[strcspn(item->name, "\n")] = '\0';
|
|
|
|
if (!fgets(line, LINESIZE, stdin)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
item->price = strtof(line, NULL);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-10-01 12:01:13 +00:00
|
|
|
int main() {
|
2024-10-02 18:39:17 +00:00
|
|
|
struct pizza menu[MENU_SIZE];
|
|
|
|
char search[LINESIZE];
|
2024-10-02 12:27:38 +00:00
|
|
|
int count = 0;
|
|
|
|
|
2024-10-02 18:39:17 +00:00
|
|
|
printf("Zadaj hladanu surovinu:\n");
|
|
|
|
if (!fgets(search, LINESIZE, stdin)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
search[strcspn(search, "\n")] = '\0';
|
2024-10-02 18:26:34 +00:00
|
|
|
|
2024-10-02 19:05:32 +00:00
|
|
|
printf("Zadaj jedalny listok:");
|
2024-10-02 18:39:17 +00:00
|
|
|
while (count < MENU_SIZE && read_pizza(&menu[count])) {
|
|
|
|
count++;
|
|
|
|
}
|
2024-10-02 18:31:47 +00:00
|
|
|
|
2024-10-02 18:39:17 +00:00
|
|
|
int found_count = 0;
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
if (contains_normalized(menu[i].name, search)) {
|
2024-10-02 19:05:32 +00:00
|
|
|
printf("\n%s\n%.2f\n", menu[i].name, menu[i].price);
|
2024-10-02 18:39:17 +00:00
|
|
|
found_count++;
|
2024-10-02 17:32:07 +00:00
|
|
|
}
|
2024-10-02 16:59:35 +00:00
|
|
|
}
|
|
|
|
|
2024-10-02 18:42:16 +00:00
|
|
|
if (found_count == 0) {
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2024-10-02 12:33:13 +00:00
|
|
|
printf("Nacitanych %d poloziek.\n", count);
|
2024-10-01 12:01:13 +00:00
|
|
|
return 0;
|
2024-10-02 18:56:18 +00:00
|
|
|
}
|