first commit

This commit is contained in:
Alina Konoval 2025-09-28 11:19:21 +02:00
commit 233adec10f
3 changed files with 77 additions and 0 deletions

BIN
du1/program Executable file

Binary file not shown.

70
du1/program.c Normal file
View File

@ -0,0 +1,70 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#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;
}

7
du1/vstup.txt Normal file
View File

@ -0,0 +1,7 @@
bryndz
8rynd20va P1zza
7.50
Ja8lkov4 Pizza
6.50
5penatov3 kal2on3
8.20