From f3f60d509dfdf71fe4d175c8d8cf35246a1f7ebc Mon Sep 17 00:00:00 2001 From: Matej Hajduk Date: Wed, 24 Sep 2025 14:20:44 +0200 Subject: [PATCH] a --- du1/program.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/du1/program.c b/du1/program.c index 114dd07..a5e2934 100644 --- a/du1/program.c +++ b/du1/program.c @@ -1,4 +1,64 @@ #include -int main(){ - +#include +#include + +#define LINE_SIZE 200 + +// meni cisla na znaky a aj velke na male +void normalize(char *z) { + char cis[] = "013456789"; + char pis[] = "oieasgtbq"; + + for (int i = 0; z[i]; i++) { + char x = tolower(z[i]); + + + int found = 0; + for (int j = 0; j < 9; j++) { + if (x == cis[j]) { + z[i] = pis[j]; + found = 1; + break; + } + } + + //na male pismeno + if (!found) { + z[i] = x; + } + } } + +int main() { + char h[LINE_SIZE]; + char line[LINE_SIZE]; + char j[LINE_SIZE]; + char price[LINE_SIZE]; + int count = 0; + + printf("Zadaj hladanu surovinu:\n"); + if (!fgets(h, LINE_SIZE, stdin)) return 0; + h[strcspn(h, "\n")] = 0; + normalize(h); + + printf("Zadaj jedalny listok:\n"); + while (1) { + if (!fgets(j, LINE_SIZE, stdin)) break; + j[strcspn(j, "\n")] = 0; + if (strlen(j) == 0) break; + if (!fgets(price, LINE_SIZE, stdin)) break; + price[strcspn(price, "\n")] = 0; + char norm_dish[LINE_SIZE]; + strcpy(norm_dish, j); + normalize(norm_dish); + if (strstr(norm_dish, h) != NULL) { + printf("%s\n", j); + printf("%s\n", price); + count++; + } + } + + printf("Nacitanych %d poloziek.\n", count); + return 0; +} +