usaa24/cv1/program.c

71 lines
2.1 KiB
C

#include <stdio.h>
#include <string.h>
#include <ctype.h>
// Funkcia na kontrolu ekvivalentnosti znakov podľa pravidiel Hack3r scr1pt
int isHack3rEquivalent(char c1, char c2) {
c1 = tolower(c1);
c2 = tolower(c2);
if (c1 == c2) return 1;
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;
}
// Funkcia na kontrolu, či názov jedla obsahuje hľadanú surovinu
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++) {
int match = 1;
for (int j = 0; j < search_len; j++) {
if (!isHack3rEquivalent(name[i + j], search[j])) {
match = 0;
break;
}
}
if (match) return 1;
}
return 0;
}
int main() {
char search[100];
char name[100];
char price[20];
int count = 0;
// Vstup pre hľadanú surovinu
printf("Zadaj hladanu surovinu:\n");
fgets(search, sizeof(search), stdin);
search[strcspn(search, "\n")] = 0;
printf("Zadaj jedalny listok:\n");
// Spracovanie jedálneho lístka
while (fgets(name, sizeof(name), stdin)) {
if (fgets(price, sizeof(price), stdin) == NULL || strlen(name) == 0) {
printf("Chyba pri nacitani.\n");
break;
}
name[strcspn(name, "\n")] = 0;
price[strcspn(price, "\n")] = 0;
if (isHack3rMatch(name, search)) {
printf("%s\n%s\n", name, price);
}
count++;
}
printf("Nacitanych %d poloziek.\n", count);
return 0;
}