From b69a502e1ed4c470bc873e75271855569fd8245e Mon Sep 17 00:00:00 2001 From: Samuel Weber Date: Sun, 29 Sep 2024 10:17:52 +0200 Subject: [PATCH] test --- cv1/program.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/cv1/program.c b/cv1/program.c index e69de29..bc90c8c 100644 --- a/cv1/program.c +++ b/cv1/program.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include + +#define MAX_LENGTH 100 + +void decode_hacker_script(const char *input, char *output) { + + int j = 0; + for (int i = 0; input[i]; i++) { + char c = tolower(input[i]); + if (c == 'o' || c == '0') output[j++] = 'o'; + else if (c == 'i' || c == '1') output[j++] = 'i'; + else if (c == 'z' || c == '2') output[j++] = 'z'; + else if (c == 'e' || c == '3') output[j++] = 'e'; + else if (c == 'a' || c == '4') output[j++] = 'a'; + else if (c == 's' || c == '5') output[j++] = 's'; + else if (c == 'b' || c == '6' || c == '8') output[j++] = 'b'; + else if (c == 't' || c == '7') output[j++] = 't'; + else if (c == 'q' || c == '9') output[j++] = 'q'; + else output[j++] = c; + } + output[j] = '\0'; +} + +int main() { + char search_item[MAX_LENGTH], menu_item[MAX_LENGTH], price[MAX_LENGTH]; + char decoded_item[MAX_LENGTH], decoded_search[MAX_LENGTH]; + int count = 0; + + printf("Zadaj hladanu surovinu:\n"); + scanf("%s", search_item); + decode_hacker_script(search_item, decoded_search); + + printf("Zadaj jedalny listok (ukonci prázdnym riadkom):\n"); + + while (1) { + + if (fgets(menu_item, sizeof(menu_item), stdin) == NULL || strlen(menu_item) == 0) { + break; + } + + menu_item[strcspn(menu_item, "\n")] = 0; + + + if (fgets(price, sizeof(price), stdin) == NULL || strlen(price) == 0) { + break; + + price[strcspn(price, "\n")] = 0; + + + decode_hacker_script(menu_item, decoded_item); + + if (strstr(decoded_item, decoded_search) != NULL) { + printf("%s\n%s\n", menu_item, price); + count++; + } + } + + + printf("Nacitanych %d poloziek.\n", count); + + return 0; +}