103 lines
2.4 KiB
C
103 lines
2.4 KiB
C
#include <stdio.h>
|
|
#include <ctype.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
#define LINE_SIZE 100
|
|
#define MAXIT 100
|
|
|
|
struct pizza{
|
|
float prize;
|
|
char name[LINE_SIZE];
|
|
};
|
|
/* structura jednej polozky*/
|
|
|
|
|
|
|
|
char hacker_script(char c){
|
|
c = tolower((unsigned char)c);
|
|
switch(c){
|
|
case '0': return 'o';
|
|
case '1': return 'i';
|
|
case '2': return 'z';
|
|
case '3': return 'e';
|
|
case '4': return 'a';
|
|
case '5': return 's';
|
|
case '6': return 'b';
|
|
case '7': return 't';
|
|
case '8': return 'b';
|
|
case '9': return 'q';
|
|
default: return c;}
|
|
}
|
|
/*hacker script nam bude vymenovat cisla na bukvy*/
|
|
|
|
|
|
|
|
void normalize(const char *source, char *dest){
|
|
int i =0;
|
|
while(source[i]!='\0'){ /* tu je cyklus ktory precahdza slovom a normalizuje ho*/
|
|
dest[i]= hacker_script(source[i]);
|
|
i++;
|
|
}
|
|
dest[i]='\0'; ///ked slovo konci, cyklus tiez skonci a na konci bude terminator
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int read_pizza(struct pizza *item){
|
|
char line_1[LINE_SIZE]; /// pre name
|
|
char line_2[LINE_SIZE]; /// pre price
|
|
|
|
if (fgets(line_1,LINE_SIZE,stdin)==NULL) return 0; /// nacitava name, ak line_1 bude null tak nastala chyba
|
|
if (fgets(line_2,LINE_SIZE,stdin)==NULL) return 0;
|
|
|
|
line_1[strcspn(line_1,"\n")] = '\0'; /// ukoncuje terminatorom
|
|
line_2[strcspn(line_2,"\n")] = '\0';
|
|
|
|
float price = 0.0;
|
|
if (sscanf(line_2, "%f", &price)!=1) return 0;// nacitava len float number
|
|
|
|
strcpy(item->name, line_1);
|
|
item->prize = price; // uklada name a price do itemu
|
|
|
|
return 1;
|
|
}
|
|
|
|
|
|
int main(){
|
|
char search[LINE_SIZE];
|
|
char normal_search[LINE_SIZE];
|
|
|
|
struct pizza list[MAXIT];
|
|
int cnt = 0;
|
|
|
|
printf("Zadaj hladanu surovinu:\n");
|
|
if (fgets(search, LINE_SIZE, stdin)==NULL) return 0;
|
|
search[strcspn(search,"\n")] = '\0';
|
|
|
|
normalize(search, normal_search); // normalizujeme nas hladany prvok
|
|
|
|
printf("Zadaj jedalny listok:\n");
|
|
|
|
|
|
while(cnt<MAXIT&&read_pizza(&list[cnt])){ cnt++;} // ak cnt menej ako MAXIT aj je nacitana jedna polozka
|
|
|
|
for (int i =0;i<cnt; i++){
|
|
char normal_name[LINE_SIZE];
|
|
normalize(list[i].name, normal_name); // normalizujeme meno
|
|
|
|
if (strstr(normal_name, normal_search) != NULL) { // ak mame to co hladame
|
|
printf("%s\n", list[i].name);
|
|
printf("%.2f\n", list[i].prize); // vyprintujeme
|
|
}
|
|
|
|
} // ak ne bude nic podobne, cyklus po nacitavani vsetkych poloziek ukonci
|
|
|
|
printf("Nacitanych %d poloziek.\n", cnt); // vypise cislo poloziek
|
|
return 0;
|
|
}
|