2024-10-02 13:51:04 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define LINESIZE 100
|
|
|
|
#define MENU_SIZE 100
|
|
|
|
|
|
|
|
struct pizza {
|
|
|
|
float prize;
|
|
|
|
char name[LINESIZE];
|
|
|
|
};
|
|
|
|
|
|
|
|
char hacker_script(char c) {
|
2024-10-02 14:16:02 +00:00
|
|
|
if (c >= 'A' && c <= 'Z') c += 32; // Преобразование к нижнему регистру
|
2024-10-02 13:51:04 +00:00
|
|
|
switch (c) {
|
|
|
|
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 14:08:44 +00:00
|
|
|
case 'b': return '6';
|
2024-10-02 13:51:04 +00:00
|
|
|
case 't': return '7';
|
2024-10-02 14:16:02 +00:00
|
|
|
case '8': return '8';
|
2024-10-02 13:51:04 +00:00
|
|
|
case 'q': return '9';
|
2024-10-02 14:08:44 +00:00
|
|
|
default: return c;
|
2024-10-02 13:51:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void normalize_string(const char* input, char* output) {
|
2024-10-02 14:08:44 +00:00
|
|
|
int i = 0;
|
2024-10-02 14:16:02 +00:00
|
|
|
while (input[i] != '\0' && input[i] != '\n') { // Убираем '\n'
|
2024-10-02 13:51:04 +00:00
|
|
|
output[i] = hacker_script(input[i]);
|
2024-10-02 14:08:44 +00:00
|
|
|
i++;
|
2024-10-02 13:51:04 +00:00
|
|
|
}
|
2024-10-02 14:16:02 +00:00
|
|
|
output[i] = '\0'; // Завершаем строку
|
2024-10-02 13:51:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int read_pizza(struct pizza* item) {
|
|
|
|
char line[LINESIZE];
|
2024-10-02 14:08:44 +00:00
|
|
|
if (fgets(line, sizeof(line), stdin) == NULL) return 0;
|
2024-10-02 13:51:04 +00:00
|
|
|
|
2024-10-02 14:16:02 +00:00
|
|
|
normalize_string(line, item->name); // Преобразуем название
|
|
|
|
|
2024-10-02 14:08:44 +00:00
|
|
|
if (fgets(line, sizeof(line), stdin) == NULL) return 0;
|
2024-10-02 14:16:02 +00:00
|
|
|
item->prize = strtof(line, NULL); // Преобразуем цену
|
2024-10-02 13:51:04 +00:00
|
|
|
|
2024-10-02 14:16:02 +00:00
|
|
|
return (item->prize > 0) ? 1 : 0; // Успех или ошибка
|
2024-10-02 14:12:41 +00:00
|
|
|
}
|
2024-10-02 14:16:02 +00:00
|
|
|
|
2024-10-02 13:51:04 +00:00
|
|
|
int find_string(const char* heap, const char* needle) {
|
|
|
|
char normalized_heap[LINESIZE];
|
|
|
|
char normalized_needle[LINESIZE];
|
|
|
|
normalize_string(heap, normalized_heap);
|
|
|
|
normalize_string(needle, normalized_needle);
|
|
|
|
|
|
|
|
return strstr(normalized_heap, normalized_needle) != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
struct pizza menu[MENU_SIZE];
|
|
|
|
int item_count = 0;
|
|
|
|
|
2024-10-02 14:08:44 +00:00
|
|
|
char search_term[LINESIZE];
|
2024-10-02 14:16:02 +00:00
|
|
|
printf("Zadaj hladanu surovinu:\n"); // Первое сообщение
|
2024-10-02 13:51:04 +00:00
|
|
|
fgets(search_term, sizeof(search_term), stdin);
|
2024-10-02 14:08:44 +00:00
|
|
|
|
2024-10-02 14:16:02 +00:00
|
|
|
// Удаляем '\n' из поискового запроса
|
2024-10-02 14:08:44 +00:00
|
|
|
search_term[strcspn(search_term, "\n")] = '\0';
|
2024-10-02 13:51:04 +00:00
|
|
|
|
2024-10-02 14:16:02 +00:00
|
|
|
printf("Zadaj jedalny listok:\n"); // Второе сообщение
|
2024-10-02 13:51:04 +00:00
|
|
|
while (item_count < MENU_SIZE && read_pizza(&menu[item_count])) {
|
|
|
|
item_count++;
|
|
|
|
}
|
|
|
|
|
2024-10-02 14:16:02 +00:00
|
|
|
// Флаг для проверки, был ли найден хотя бы один элемент
|
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
// Печать подходящих элементов
|
2024-10-02 13:51:04 +00:00
|
|
|
for (int i = 0; i < item_count; i++) {
|
2024-10-02 14:08:44 +00:00
|
|
|
if (find_string(menu[i].name, search_term)) {
|
2024-10-02 13:51:04 +00:00
|
|
|
printf("%s\n%.2f\n", menu[i].name, menu[i].prize);
|
2024-10-02 14:16:02 +00:00
|
|
|
found = 1; // Найдено совпадение
|
2024-10-02 13:51:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-02 14:16:02 +00:00
|
|
|
// Если совпадений нет, ничего не выводится, иначе выводим количество
|
|
|
|
if (found) {
|
|
|
|
printf("Nacitanych %d poloziek.\n", item_count);
|
|
|
|
} else {
|
|
|
|
// Выводим только количество, если совпадений нет
|
|
|
|
printf("Nacitanych %d poloziek.\n", item_count);
|
|
|
|
}
|
|
|
|
|
2024-10-02 13:51:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|