commit d951b5144414ae83e0628c3c38c8d2d0cd0af1ec Author: Marat Izmailov Date: Wed Oct 2 13:49:18 2024 +0000 Add program.c diff --git a/program.c b/program.c new file mode 100644 index 0000000..04228fa --- /dev/null +++ b/program.c @@ -0,0 +1,80 @@ +#include +#include +#include + +#define LINESIZE 100 +#define MENU_SIZE 100 + +struct pizza { + float prize; + char name[LINESIZE]; +}; + +char hacker_script(char c) { + if (c >= 'A' && c <= 'Z') return c + 32; // Convert uppercase to lowercase + 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'; + case 'b': return '6'; // Single mapping for 'b' + case 't': return '7'; + case '8': return '8'; // Added mapping for '8' + case 'q': return '9'; + default: return c; // Return unchanged for other characters + } +} + +void normalize_string(const char* input, char* output) { + for (int i = 0; input[i] != '\0'; i++) { + output[i] = hacker_script(input[i]); + } + output[strlen(input)] = '\0'; // Null-terminate +} + +int read_pizza(struct pizza* item) { + char line[LINESIZE]; + if (fgets(line, sizeof(line), stdin) == NULL) return 0; // End of input + + normalize_string(line, item->name); // Normalize the name + + if (fgets(line, sizeof(line), stdin) == NULL) return 0; // Read price + item->prize = strtof(line, NULL); // Convert to float + + return (item->prize > 0) ? 1 : 0; // Return success or failure +} + +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; + + char search_term[LINESIZE]; // Renamed to avoid conflict + printf("Zadaj hladanu surovinu:\n"); + fgets(search_term, sizeof(search_term), stdin); + + printf("Zadaj jedalny listok:\n"); + while (item_count < MENU_SIZE && read_pizza(&menu[item_count])) { + item_count++; + } + + // Print matching items + for (int i = 0; i < item_count; i++) { + if (find_string(menu[i].name, search_term)) { // Use the new function name + printf("%s\n%.2f\n", menu[i].name, menu[i].prize); + } + } + + printf("Nacitanych %d poloziek.\n", item_count); + return 0; +} \ No newline at end of file