Final
This commit is contained in:
parent
3858a4cc32
commit
6d745dc623
128
cv1/program.c
Normal file → Executable file
128
cv1/program.c
Normal file → Executable file
@ -1,11 +1,117 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
#include <stdio.h>
|
||||||
#define LINESIZE 100
|
#include <string.h>
|
||||||
struct pizza {
|
#include <stdlib.h>
|
||||||
float prize;
|
|
||||||
char name[LINESIZE];
|
struct item {
|
||||||
};
|
char name[50];
|
||||||
|
float price;
|
||||||
|
|
||||||
int main(){
|
};
|
||||||
}
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user