2024-10-03 21:16:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
2024-10-03 21:02:43 +00:00
|
|
|
|
2024-10-03 21:29:33 +00:00
|
|
|
// Funkcia na kontrolu ekvivalentnosti znakov podľa pravidiel Hack3r scr1pt
|
2024-10-03 21:16:54 +00:00
|
|
|
int isHack3rEquivalent(char c1, char c2) {
|
|
|
|
c1 = tolower(c1);
|
|
|
|
c2 = tolower(c2);
|
|
|
|
|
2024-10-03 21:29:33 +00:00
|
|
|
if (c1 == c2) return 1;
|
2024-10-03 21:24:34 +00:00
|
|
|
if ((c1 == '0' && c2 == 'o') || (c1 == 'o' && c2 == '0')) return 1;
|
|
|
|
if ((c1 == '1' && c2 == 'i') || (c1 == 'i' && c2 == '1')) return 1;
|
|
|
|
if ((c1 == '2' && c2 == 'z') || (c1 == 'z' && c2 == '2')) return 1;
|
|
|
|
if ((c1 == '3' && c2 == 'e') || (c1 == 'e' && c2 == '3')) return 1;
|
|
|
|
if ((c1 == '4' && c2 == 'a') || (c1 == 'a' && c2 == '4')) return 1;
|
|
|
|
if ((c1 == '5' && c2 == 's') || (c1 == 's' && c2 == '5')) return 1;
|
|
|
|
if ((c1 == '7' && c2 == 't') || (c1 == 't' && c2 == '7')) return 1;
|
|
|
|
if ((c1 == '8' && c2 == 'b') || (c1 == 'b' && c2 == '8')) return 1;
|
|
|
|
return 0;
|
2024-10-03 21:16:54 +00:00
|
|
|
}
|
|
|
|
|
2024-10-03 21:29:33 +00:00
|
|
|
// Funkcia na kontrolu, či názov jedla obsahuje hľadanú surovinu
|
2024-10-03 21:16:54 +00:00
|
|
|
int isHack3rMatch(const char *name, const char *search) {
|
|
|
|
int name_len = strlen(name);
|
|
|
|
int search_len = strlen(search);
|
|
|
|
|
|
|
|
for (int i = 0; i <= name_len - search_len; i++) {
|
2024-10-03 21:29:33 +00:00
|
|
|
int match = 1;
|
2024-10-03 21:16:54 +00:00
|
|
|
for (int j = 0; j < search_len; j++) {
|
|
|
|
if (!isHack3rEquivalent(name[i + j], search[j])) {
|
2024-10-03 21:29:33 +00:00
|
|
|
match = 0;
|
2024-10-03 21:16:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-10-03 21:29:33 +00:00
|
|
|
if (match) return 1;
|
2024-10-03 21:16:54 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2024-10-03 21:29:33 +00:00
|
|
|
char search[100];
|
|
|
|
char name[100];
|
|
|
|
char price[20];
|
|
|
|
int count = 0;
|
2024-10-03 21:16:54 +00:00
|
|
|
|
2024-10-03 21:29:33 +00:00
|
|
|
// Vstup pre hľadanú surovinu
|
2024-10-03 21:28:06 +00:00
|
|
|
printf("Zadaj hladanu surovinu:\n");
|
2024-10-03 21:16:54 +00:00
|
|
|
fgets(search, sizeof(search), stdin);
|
2024-10-03 21:29:33 +00:00
|
|
|
search[strcspn(search, "\n")] = 0;
|
2024-10-03 21:16:54 +00:00
|
|
|
|
2024-10-03 21:28:06 +00:00
|
|
|
printf("Zadaj jedalny listok:\n");
|
2024-10-03 21:16:54 +00:00
|
|
|
|
2024-10-03 21:29:33 +00:00
|
|
|
// Spracovanie jedálneho lístka
|
2024-10-03 21:16:54 +00:00
|
|
|
while (fgets(name, sizeof(name), stdin)) {
|
|
|
|
if (fgets(price, sizeof(price), stdin) == NULL || strlen(name) == 0) {
|
2024-10-03 21:29:33 +00:00
|
|
|
printf("Chyba pri nacitani.\n");
|
2024-10-03 21:16:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
name[strcspn(name, "\n")] = 0;
|
|
|
|
price[strcspn(price, "\n")] = 0;
|
|
|
|
|
|
|
|
if (isHack3rMatch(name, search)) {
|
2024-10-03 21:29:33 +00:00
|
|
|
printf("%s\n%s\n", name, price);
|
2024-10-03 21:16:54 +00:00
|
|
|
}
|
2024-10-03 21:29:33 +00:00
|
|
|
count++;
|
2024-10-03 21:16:54 +00:00
|
|
|
}
|
|
|
|
|
2024-10-03 21:29:33 +00:00
|
|
|
printf("Nacitanych %d poloziek.\n", count);
|
2024-10-03 21:25:32 +00:00
|
|
|
return 0;
|
2024-10-03 21:18:50 +00:00
|
|
|
}
|