usaa24/cv1/program.c

84 lines
2.0 KiB
C
Raw Normal View History

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:08:44 +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:08:44 +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;
while (input[i] != '\0' && input[i] != '\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:08:44 +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:08:44 +00:00
normalize_string(line, item->name);
if (fgets(line, sizeof(line), stdin) == NULL) return 0;
item->prize = strtof(line, NULL);
2024-10-02 13:51:04 +00:00
2024-10-02 14:08:44 +00:00
return (item->prize > 0) ? 1 : 0;
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 13:51:04 +00:00
printf("Zadaj hladanu surovinu:\n");
fgets(search_term, sizeof(search_term), stdin);
2024-10-02 14:08:44 +00:00
search_term[strcspn(search_term, "\n")] = '\0';
2024-10-02 13:51:04 +00:00
printf("Zadaj jedalny listok:\n");
while (item_count < MENU_SIZE && read_pizza(&menu[item_count])) {
item_count++;
}
2024-10-02 14:08:44 +00:00
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);
}
}
printf("Nacitanych %d poloziek.\n", item_count);
return 0;
}
2024-10-02 14:09:40 +00:00
}