From 6d745dc62309cb44cf509a031229b0e43b6ca192 Mon Sep 17 00:00:00 2001 From: vj586da Date: Wed, 6 Oct 2021 14:17:38 +0200 Subject: [PATCH] Final --- cv1/program.c | 128 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 117 insertions(+), 11 deletions(-) mode change 100644 => 100755 cv1/program.c diff --git a/cv1/program.c b/cv1/program.c old mode 100644 new mode 100755 index 62b6583..99fba0f --- a/cv1/program.c +++ b/cv1/program.c @@ -1,11 +1,117 @@ -#include - -#define LINESIZE 100 -struct pizza { - float prize; - char name[LINESIZE]; -}; - - -int main(){ -} + +#include +#include +#include + +struct item { + char name[50]; + float price; + +}; + +struct backup_item { + char name[50]; + float price; + +}; + +#define NUMBER_OF_MEALS 20 + +int main(){ + char sign[] = {'o','i','z','e','a','s','b','t','b','q'}; + char secret[]={'0','1','2','3','4','5','6','7','8','9'}; + + char input_search[20]; + //initialize input_search + struct item menu[NUMBER_OF_MEALS]; + struct backup_item backup_menu[NUMBER_OF_MEALS]; + //initialize menu + //for(int i = 0; i < NUMBER_OF_MEALS; i++){ + memset(menu, 0,sizeof(struct item)*NUMBER_OF_MEALS); + memset(backup_menu, 0,sizeof(struct item)*NUMBER_OF_MEALS); + //printf("%s\n",menu->name); + //menu[i] = {'c','c'}; + + //} + + printf("Zadaj hladanu surovinu: "); + fgets (input_search, 20, stdin); + + printf("Zadaj jedalny listok:\n"); + + char temp[10]; + //initialize temp + int meal_counter = 0; + //load menu + while(1){ + fgets (menu[meal_counter].name, 20, stdin); + if(menu[meal_counter].name[0] == '\n'){ + break; + } + fgets (temp, 10, stdin); + menu[meal_counter].price = strtof(temp, NULL); + + + meal_counter++; + + } + + //make copy of menu + for (int i = 0 ; i < meal_counter; i++){ + strcpy(backup_menu[i].name, menu[i].name); + backup_menu[i].price = menu[i].price; + } + /*optimize backup_menu*/ + //each item.name + for(int i = 0 ; i < meal_counter; i++){ + //each item.name letter + for(int j = 0; j < strlen(backup_menu[i].name)-1; j++){ + //each letter in secret[] + for (int k = 0; k < 10; k++){ + //compare secret letter with item.name letters + if(backup_menu[i].name[j] == secret[k]){ + //swap letter in item.name with sign[] if match + backup_menu[i].name[j] = sign[k]; + } + } + } + + } + + + int input_search_size = strlen(input_search); + int match_counter = 1; + int new_start = 0; + //find match in menu + for(int i = 0; i < meal_counter; i++){ + new_start = 0; + match_counter = 1; + //loop through each item name + for(int j = 0; j < strlen(backup_menu[i].name); j++){ + //if some word starts with first letter of input + if(backup_menu[i].name[j] == input_search[0]){ + new_start = j; + //loop through each letter in input_search + for(int k = 0; k < input_search_size; k++){ + + if(backup_menu[i].name[new_start] == input_search[k]){ + match_counter++; + + } + new_start++; + } + if(match_counter == input_search_size){ + printf("%s%.2f\n",menu[i].name,menu[i].price); + + break; + } + + } + + } + + } + printf("Nacitanych %d poloziek.",meal_counter); + + return 0; +}