usaa24/cv1/program.c

79 lines
2.3 KiB
C
Raw Normal View History

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-04 12:20:12 +00:00
// Funkcia na porovnanie znakov podľa pravidiel Hack3r scr1pt
2024-10-03 21:16:54 +00:00
int isHack3rEquivalent(char c1, char c2) {
2024-10-04 12:02:06 +00:00
char table[256] = {0};
table['0'] = 'o'; table['o'] = '0';
table['1'] = 'i'; table['i'] = '1';
table['2'] = 'z'; table['z'] = '2';
table['3'] = 'e'; table['e'] = '3';
table['4'] = 'a'; table['a'] = '4';
table['5'] = 's'; table['s'] = '5';
table['6'] = 'b'; table['b'] = '6';
table['7'] = 't'; table['t'] = '7';
table['8'] = 'b'; table['b'] = '8';
table['9'] = 'q'; table['q'] = '9';
2024-10-03 21:16:54 +00:00
c1 = tolower(c1);
c2 = tolower(c2);
2024-10-03 21:29:33 +00:00
if (c1 == c2) return 1;
2024-10-04 12:02:06 +00:00
return table[(unsigned char)c1] == c2;
2024-10-03 21:16:54 +00:00
}
2024-10-04 12:20:12 +00:00
// Funkcia na zistenie, či sa reťazec hľadanej suroviny nachádza v názve jedla
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-04 12:02:06 +00:00
if (match) return 1;
2024-10-03 21:16:54 +00:00
}
return 0;
}
2024-10-04 12:20:12 +00:00
int main() {
2024-10-04 12:02:06 +00:00
char line[200];
char name[100];
char price[20];
int count = 0;
2024-10-03 21:16:54 +00:00
2024-10-03 21:28:06 +00:00
printf("Zadaj hladanu surovinu:\n");
2024-10-04 12:02:06 +00:00
fgets(name, sizeof(name), stdin);
2024-10-04 12:20:12 +00:00
name[strcspn(name, "\n")] = 0; // Odstráni znak nového riadku
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-04 12:21:36 +00:00
while (1) {
// Načítanie názvu položky
if (fgets(line, sizeof(line), stdin) == NULL || strcmp(line, "\n") == 0) {
break; // Ak nie sú ďalšie riadky alebo je prázdny riadok, ukončujeme
2024-10-03 21:16:54 +00:00
}
2024-10-04 12:20:12 +00:00
line[strcspn(line, "\n")] = 0; // Odstráni znak nového riadku
// Načítanie nasledujúceho riadku, ktorý obsahuje cenu
2024-10-04 12:21:36 +00:00
if (fgets(price, sizeof(price), stdin) == NULL || strcmp(price, "\n") == 0) {
break; // Ak nie sú ďalšie riadky alebo je prázdny riadok, ukončujeme
2024-10-04 12:02:06 +00:00
}
2024-10-04 12:20:12 +00:00
price[strcspn(price, "\n")] = 0; // Odstráni znak nového riadku
2024-10-04 12:02:06 +00:00
2024-10-04 12:20:12 +00:00
// Ak je zhodná, vypíšeme názov a cenu
2024-10-04 12:02:06 +00:00
if (isHack3rMatch(line, name)) {
printf("%s\n%s\n", line, price);
2024-10-04 12:20:12 +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:31:15 +00:00
2024-10-03 21:25:32 +00:00
return 0;
2024-10-03 21:18:50 +00:00
}