2024-09-30 11:43:46 +00:00
|
|
|
|
#include <stdio.h>
|
2024-10-02 16:24:50 +00:00
|
|
|
|
#include <string.h>
|
2024-10-02 16:42:43 +00:00
|
|
|
|
#include <stdlib.h>
|
2024-10-02 08:31:44 +00:00
|
|
|
|
#include <ctype.h>
|
2024-09-30 16:41:25 +00:00
|
|
|
|
|
2024-10-02 16:42:43 +00:00
|
|
|
|
#define LINESIZE 100
|
|
|
|
|
#define MAX_PIZZAS 100
|
2024-09-30 11:43:46 +00:00
|
|
|
|
|
2024-10-02 16:42:43 +00:00
|
|
|
|
struct pizza {
|
|
|
|
|
float prize;
|
|
|
|
|
char name[LINESIZE];
|
2024-09-30 11:43:46 +00:00
|
|
|
|
};
|
|
|
|
|
|
2024-10-02 16:42:43 +00:00
|
|
|
|
char hacker_script(char c) {
|
|
|
|
|
// Перетворення відповідно до "Hack3r scr1pt"
|
|
|
|
|
switch (c) {
|
2024-10-02 16:24:50 +00:00
|
|
|
|
case 'o': return '0';
|
|
|
|
|
case 'i': return '1';
|
|
|
|
|
case 'z': return '2';
|
|
|
|
|
case 'e': return '3';
|
|
|
|
|
case 'a': return '4';
|
|
|
|
|
case 's': return '5';
|
2024-10-02 16:42:43 +00:00
|
|
|
|
case 'd': return '6';
|
2024-10-02 16:24:50 +00:00
|
|
|
|
case 't': return '7';
|
2024-10-02 16:42:43 +00:00
|
|
|
|
case 'b': return '8';
|
2024-10-02 16:24:50 +00:00
|
|
|
|
case 'q': return '9';
|
2024-10-02 16:42:43 +00:00
|
|
|
|
default: return tolower(c); // Зробити маленьким
|
2024-10-02 16:24:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-30 11:43:46 +00:00
|
|
|
|
|
2024-10-02 16:42:43 +00:00
|
|
|
|
void normalize(char *input, char *output) {
|
|
|
|
|
for (int i = 0; input[i] != '\0'; i++) {
|
|
|
|
|
output[i] = hacker_script(input[i]);
|
2024-10-02 08:31:44 +00:00
|
|
|
|
}
|
2024-10-02 16:42:43 +00:00
|
|
|
|
output[strlen(input)] = '\0'; // Завершити рядок
|
2024-10-02 16:24:50 +00:00
|
|
|
|
}
|
2024-10-02 08:31:44 +00:00
|
|
|
|
|
2024-10-02 16:42:43 +00:00
|
|
|
|
int read_pizza(struct pizza *item) {
|
|
|
|
|
char line[LINESIZE];
|
|
|
|
|
if (fgets(line, sizeof(line), stdin) == NULL) return 0;
|
|
|
|
|
|
|
|
|
|
// Зчитування назви
|
|
|
|
|
strcpy(item->name, line);
|
|
|
|
|
|
|
|
|
|
// Зчитування ціни
|
|
|
|
|
if (fgets(line, sizeof(line), stdin) == NULL) return 0;
|
|
|
|
|
|
|
|
|
|
// Перетворення рядка на float
|
|
|
|
|
item->prize = strtof(line, NULL);
|
|
|
|
|
if (item->prize == 0.0F) return 0; // Перевірка на успішність
|
|
|
|
|
|
|
|
|
|
return 1; // Успішно зчитано
|
2024-10-02 16:24:50 +00:00
|
|
|
|
}
|
2024-10-02 07:58:10 +00:00
|
|
|
|
|
2024-10-02 16:42:43 +00:00
|
|
|
|
int search_string(const char *haystack, const char *needle) {
|
|
|
|
|
for (int i = 0; haystack[i] != '\0'; i++) {
|
|
|
|
|
int j;
|
|
|
|
|
for (j = 0; needle[j] != '\0' && haystack[i + j] == needle[j]; j++);
|
|
|
|
|
if (needle[j] == '\0') return i; // Знайдено
|
2024-09-30 11:43:46 +00:00
|
|
|
|
}
|
2024-10-02 16:42:43 +00:00
|
|
|
|
return -1; // Не знайдено
|
2024-09-30 11:43:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-02 16:24:50 +00:00
|
|
|
|
int main() {
|
2024-10-02 16:42:43 +00:00
|
|
|
|
char search[LINESIZE];
|
|
|
|
|
struct pizza menu[MAX_PIZZAS];
|
|
|
|
|
char normalized_search[LINESIZE];
|
|
|
|
|
int count = 0;
|
2024-09-30 16:41:25 +00:00
|
|
|
|
|
2024-10-02 16:42:43 +00:00
|
|
|
|
printf("Zadaj hladanu surovinu:\n");
|
|
|
|
|
fgets(search, sizeof(search), stdin);
|
|
|
|
|
search[strcspn(search, "\n")] = 0; // Прибрати символ нового рядка
|
2024-10-02 16:24:50 +00:00
|
|
|
|
|
2024-10-02 16:42:43 +00:00
|
|
|
|
// Нормалізація пошукового рядка
|
|
|
|
|
normalize(search, normalized_search);
|
2024-10-02 16:24:50 +00:00
|
|
|
|
|
2024-10-02 16:42:43 +00:00
|
|
|
|
printf("Zadaj jedalny listok:\n");
|
|
|
|
|
while (read_pizza(&menu[count]) && count < MAX_PIZZAS) {
|
|
|
|
|
count++;
|
|
|
|
|
}
|
2024-10-02 16:24:50 +00:00
|
|
|
|
|
2024-10-02 16:42:43 +00:00
|
|
|
|
// Пошук і вивід результатів
|
|
|
|
|
printf("Znalezené jedlá:\n");
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
|
char normalized_name[LINESIZE];
|
|
|
|
|
normalize(menu[i].name, normalized_name);
|
|
|
|
|
if (search_string(normalized_name, normalized_search) != -1) {
|
|
|
|
|
printf("%s%.2f\n", menu[i].name, menu[i].prize);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-02 16:24:50 +00:00
|
|
|
|
|
2024-10-02 16:42:43 +00:00
|
|
|
|
printf("Nacitanych %d poloziek.\n", count);
|
2024-10-02 16:24:50 +00:00
|
|
|
|
return 0;
|
2024-10-02 08:31:44 +00:00
|
|
|
|
}
|