2024-09-26 09:48:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
char convert_to_normal(char ch) {
|
|
|
|
switch (ch) {
|
|
|
|
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 tolower(ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int contains_substring(char *food_name, char *ingredient) {
|
|
|
|
int len_food = strlen(food_name);
|
|
|
|
int len_ing = strlen(ingredient);
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i <= len_food - len_ing; i++) {
|
|
|
|
int found = 1;
|
|
|
|
for (j = 0; j < len_ing; j++) {
|
|
|
|
if (convert_to_normal(food_name[i + j]) != convert_to_normal(ingredient[j])) {
|
|
|
|
found = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found) return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2024-09-26 21:21:24 +00:00
|
|
|
|
|
|
|
int main() {
|
|
|
|
char ingredient[100];
|
2024-09-26 21:24:26 +00:00
|
|
|
char food_name[200];
|
2024-09-26 21:21:24 +00:00
|
|
|
char price[20];
|
|
|
|
int count = 0;
|
|
|
|
|
2024-09-26 21:24:26 +00:00
|
|
|
printf("Zadaj hladanu surovinu:\n");
|
|
|
|
if (!fgets(ingredient, sizeof(ingredient), stdin)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
ingredient[strcspn(ingredient, "\n")] = '\0';
|
2024-09-26 21:21:24 +00:00
|
|
|
|
|
|
|
printf("Zadaj jedalny listok:\n");
|
|
|
|
while (fgets(food_name, sizeof(food_name), stdin)) {
|
2024-09-26 21:24:26 +00:00
|
|
|
food_name[strcspn(food_name, "\n")] = '\0';
|
2024-09-26 21:21:24 +00:00
|
|
|
if (!fgets(price, sizeof(price), stdin)) {
|
|
|
|
break;
|
|
|
|
}
|
2024-09-26 21:24:26 +00:00
|
|
|
price[strcspn(price, "\n")] = '\0';
|
2024-09-26 21:21:24 +00:00
|
|
|
|
|
|
|
if (contains_substring(food_name, ingredient)) {
|
|
|
|
printf("%s\n%s\n", food_name, price);
|
|
|
|
}
|
|
|
|
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Nacitanych %d poloziek.\n", count);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|