commit 0d816c08c67ea1cefdeceb129201912fdf8c77fc Author: Deinerovych Date: Thu Sep 26 11:48:54 2024 +0200 1 diff --git a/cv1/program.c b/cv1/program.c new file mode 100644 index 0000000..65dcb02 --- /dev/null +++ b/cv1/program.c @@ -0,0 +1,65 @@ +#include +#include +#include + +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; +} + +int main() { + char ingredient[100]; + char food_name[100]; + char price[20]; + int count = 0; + + printf("Zadaj hladanu surovinu: "); + scanf("%s", ingredient); + + printf("Zadaj jedalny listok:\n"); + while (scanf("%s", food_name) != EOF) { + if (scanf("%s", price) == EOF) { + break; + } + + if (contains_substring(food_name, ingredient)) { + printf("%s\n%s\n", food_name, price); + } + + count++; + } + + printf("Nacitanych %d poloziek.\n", count); + + return 0; +} +