usaa24/cv1/program.c

64 lines
1.5 KiB
C
Raw Normal View History

2024-10-01 12:01:13 +00:00
#include <stdio.h>
2024-10-02 12:27:38 +00:00
#include <string.h>
2024-10-02 18:26:34 +00:00
#include <ctype.h>
2024-10-02 12:27:38 +00:00
2024-10-02 18:26:34 +00:00
#define MAX_INPUT_LENGTH 100
char hack3r_script_mapping[][2] = {
{'0', 'o'},
{'1', 'i'},
{'2', 'z'},
{'3', 'e'},
{'4', 'a'},
{'5', 's'},
{'6', 'b'},
{'7', 't'},
{'8', 'b'},
{'9', 'q'}
2024-10-02 12:33:13 +00:00
};
2024-10-02 12:27:38 +00:00
2024-10-01 12:01:13 +00:00
int main() {
2024-10-02 18:26:34 +00:00
char ingredient[MAX_INPUT_LENGTH];
char menu_item[MAX_INPUT_LENGTH];
2024-10-02 12:27:38 +00:00
int count = 0;
2024-10-02 18:26:34 +00:00
printf("Zadaj hladanu surovinu: ");
fgets(ingredient, MAX_INPUT_LENGTH, stdin);
2024-10-02 18:36:14 +00:00
ingredient[strcspn(ingredient, "\n")] = 0;
2024-10-02 18:26:34 +00:00
2024-10-02 18:36:14 +00:00
printf("Zadaj jedalny listok:\n");
2024-10-02 18:31:47 +00:00
2024-10-02 18:26:34 +00:00
while (1) {
fgets(menu_item, MAX_INPUT_LENGTH, stdin);
if (feof(stdin) || strlen(menu_item) == 1) {
break;
}
2024-10-02 18:36:14 +00:00
menu_item[strcspn(menu_item, "\n")] = 0;
2024-10-02 18:26:34 +00:00
char name_hack3r[MAX_INPUT_LENGTH];
int j = 0;
for (int i = 0; menu_item[i]; i++) {
int found = 0;
for (int k = 0; k < 10; k++) {
if (menu_item[i] == hack3r_script_mapping[k][0]) {
name_hack3r[j++] = hack3r_script_mapping[k][1];
found = 1;
break;
}
}
if (!found) {
name_hack3r[j++] = tolower(menu_item[i]);
}
}
name_hack3r[j] = 0;
2024-10-02 12:27:38 +00:00
2024-10-02 18:26:34 +00:00
if (strstr(name_hack3r, ingredient) != NULL) {
printf("%s\n", menu_item);
count++;
2024-10-02 17:32:07 +00:00
}
2024-10-02 16:59:35 +00:00
}
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;
2024-10-02 18:26:34 +00:00
}