commit 233adec10fe6ede1c26473b52c412c8aa65f4472 Author: Alina Konoval Date: Sun Sep 28 11:19:21 2025 +0200 first commit diff --git a/du1/program b/du1/program new file mode 100755 index 0000000..fda8aea Binary files /dev/null and b/du1/program differ diff --git a/du1/program.c b/du1/program.c new file mode 100644 index 0000000..047860d --- /dev/null +++ b/du1/program.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include + +#define SIZE 100 + +typedef struct { + char name[SIZE]; + float price; +} Pizza; + +void strip_newline(char *s) { + size_t n = strlen(s); + n && s[n-1]=='\n' ? s[n-1]='\0' : 0; +} + +char normal_char(char c) { + char lc = tolower((unsigned char)c); + return (lc >= '0' && lc <= '9') ? "oizeasbtbq"[lc - '0'] : lc; +} + +void normal_str(const char *src, char *dst, size_t n) { + size_t i; + for (i = 0; src[i] && i + 1 < n; i++) dst[i] = normal_char(src[i]); + dst[i] = '\0'; +} + +int contains(const char *text, const char *pattern) { + size_t len_text = strlen(text), len_pat = strlen(pattern); + if (len_pat > len_text) return 0; + + for (size_t i = 0; i <= len_text - len_pat; i++) + !strncmp(text + i, pattern, len_pat) ? (void)(i = len_text) : 0; + + for (size_t i = 0; i <= len_text - len_pat; i++) + if (!strncmp(text + i, pattern, len_pat)) return 1; + return 0; +} + +int read_pizza(Pizza *p) { + char buf[SIZE]; + return (!fgets(p->name, SIZE, stdin) || !fgets(buf, SIZE, stdin)) + ? 0 + : (strip_newline(p->name), p->price = strtof(buf, NULL), 1); +} + +int main() { + char needle[SIZE], needle_norm[SIZE]; + Pizza p; + int total = 0; + + printf("Zadaj hladanu surovinu:\n"); + if (!fgets(needle, SIZE, stdin)) return printf("Nacitanych 0 poloziek.\n"), 0; + + strip_newline(needle); + normal_str(needle, needle_norm, SIZE); + + printf("Zadaj jedalny listok:\n"); + while (read_pizza(&p)) { + total++; + char name_norm[SIZE]; + normal_str(p.name, name_norm, SIZE); + contains(name_norm, needle_norm) ? printf("%s\n%.2f\n", p.name, p.price) : 0; + } + + printf("Nacitanych %d poloziek.\n", total); + return 0; +} + diff --git a/du1/vstup.txt b/du1/vstup.txt new file mode 100644 index 0000000..4210fa1 --- /dev/null +++ b/du1/vstup.txt @@ -0,0 +1,7 @@ +bryndz +8rynd20va P1zza +7.50 +Ja8lkov4 Pizza +6.50 +5penatov3 kal2on3 +8.20