2020-09-29 17:23:12 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2020-09-30 18:31:17 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdlib.h>
|
2020-09-29 17:23:12 +00:00
|
|
|
|
|
|
|
#define LINESIZE 100
|
|
|
|
#define LINE_SIZE 100
|
2020-10-04 19:54:55 +00:00
|
|
|
#define POCET_JEDAL 100
|
2020-09-29 17:23:12 +00:00
|
|
|
struct pizza {
|
|
|
|
float prize;
|
|
|
|
char name[LINESIZE];
|
|
|
|
};
|
2020-10-04 21:12:49 +00:00
|
|
|
void trim(char* str);
|
2020-10-04 20:26:40 +00:00
|
|
|
int search_string(const char* heap, const char* needle);
|
2020-10-04 19:32:23 +00:00
|
|
|
int read_pizza(struct pizza* item);
|
2020-10-04 19:41:14 +00:00
|
|
|
char hacker_script(char c);
|
2020-09-30 20:00:48 +00:00
|
|
|
int main(){
|
2020-10-03 11:03:18 +00:00
|
|
|
struct pizza jedalny_listok[POCET_JEDAL];
|
2020-09-29 17:23:12 +00:00
|
|
|
memset(jedalny_listok, 0,sizeof(struct pizza)*POCET_JEDAL);
|
2020-10-04 20:26:40 +00:00
|
|
|
int counter;
|
2020-09-29 17:23:12 +00:00
|
|
|
char line[LINE_SIZE];
|
2020-10-04 19:32:23 +00:00
|
|
|
memset(line,0,LINE_SIZE);
|
2020-10-04 19:54:55 +00:00
|
|
|
printf("Zadaj hladanu surovinu:\n");
|
2020-10-04 19:32:23 +00:00
|
|
|
char* r = fgets(line,LINE_SIZE,stdin);
|
2020-10-04 21:12:49 +00:00
|
|
|
trim(line);
|
2020-10-04 19:32:23 +00:00
|
|
|
if(r != NULL && line[1] != 0){
|
2020-10-04 19:54:55 +00:00
|
|
|
printf("Zadaj jedalny listok\n");
|
2020-10-04 19:32:23 +00:00
|
|
|
struct pizza item;
|
2020-10-04 21:12:49 +00:00
|
|
|
counter=0;
|
2020-10-04 19:32:23 +00:00
|
|
|
while(read_pizza(&item)){
|
2020-10-04 21:12:49 +00:00
|
|
|
strcpy(jedalny_listok[counter].name, item.name);
|
|
|
|
jedalny_listok[counter].prize=item.prize;
|
|
|
|
//printf("%s",jedalny_listok[counter].name);
|
|
|
|
//printf("%s",item.name);
|
2020-10-04 20:26:40 +00:00
|
|
|
counter += 1;
|
2020-10-04 19:32:23 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-04 21:12:49 +00:00
|
|
|
//printf("%d\n",counter);
|
2020-10-04 20:26:40 +00:00
|
|
|
for(int i=0;i<counter;i++){
|
|
|
|
if(search_string(jedalny_listok[i].name,line)!=-1){
|
|
|
|
printf("%s\n",jedalny_listok[i].name);
|
|
|
|
printf("%.2f\n",jedalny_listok[i].prize);
|
2020-10-04 21:12:49 +00:00
|
|
|
//printf("daco\n");
|
2020-10-04 20:26:40 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-04 21:12:49 +00:00
|
|
|
//printf("%s",line);
|
2020-10-04 20:26:40 +00:00
|
|
|
printf("Nacitanych %d poloziek",counter);
|
|
|
|
}
|
2020-10-04 21:12:49 +00:00
|
|
|
void trim(char* str){
|
|
|
|
int i=0;
|
|
|
|
while(str[i]!='\n'&&str[i]!=0){
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
str[i]=0;
|
|
|
|
}
|
2020-10-04 19:32:23 +00:00
|
|
|
int search_string(const char* heap, const char* needle){
|
|
|
|
int M=strlen(needle);
|
|
|
|
int N=strlen(heap);
|
2020-10-04 19:41:14 +00:00
|
|
|
for(int i=0;i<=N-M;i++){
|
2020-10-04 21:12:49 +00:00
|
|
|
int j;
|
|
|
|
for(j=0;j<M;j++){
|
|
|
|
//printf("heap:%c\n",hacker_script(heap[i+j]));
|
|
|
|
//printf("needle:%c\n",hacker_script(needle[j]));
|
|
|
|
if(hacker_script(heap[i+j])!=hacker_script(needle[j])){
|
|
|
|
break;
|
2020-10-04 19:32:23 +00:00
|
|
|
}
|
2020-10-04 21:12:49 +00:00
|
|
|
}
|
2020-10-04 19:32:23 +00:00
|
|
|
if(j==M){
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return -1;
|
|
|
|
}
|
2020-09-30 20:24:59 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-04 19:32:23 +00:00
|
|
|
int read_pizza(struct pizza* item){
|
|
|
|
char line[LINE_SIZE];
|
|
|
|
memset(line,0,LINE_SIZE);
|
|
|
|
char* r = fgets(line,LINE_SIZE,stdin);
|
2020-10-04 21:12:49 +00:00
|
|
|
trim(line);
|
2020-10-04 19:32:23 +00:00
|
|
|
if(r != NULL && line[1] != 0){
|
|
|
|
char line2[LINE_SIZE];
|
|
|
|
memset(line2,0,LINE_SIZE);
|
|
|
|
fgets(line2,LINE_SIZE,stdin);
|
|
|
|
float value = strtof(line2,NULL);
|
2020-09-30 20:00:48 +00:00
|
|
|
if (value == 0.0F){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
item->prize = value;
|
|
|
|
strcpy(item->name, line);
|
|
|
|
return 1;
|
2020-09-30 18:31:17 +00:00
|
|
|
}
|
2020-10-04 19:32:23 +00:00
|
|
|
}
|
2020-10-04 21:12:49 +00:00
|
|
|
|
2020-09-30 18:31:17 +00:00
|
|
|
char hacker_script(char c){
|
|
|
|
char numbers[] = "0123456789";
|
|
|
|
char letters[] = "oizeasbtbq";
|
|
|
|
for (int i = 0; i < 10; i++){
|
2020-10-03 11:03:18 +00:00
|
|
|
if (c == numbers[i]){
|
2020-09-30 18:31:17 +00:00
|
|
|
return letters[i];
|
|
|
|
}
|
2020-09-29 17:23:12 +00:00
|
|
|
}
|
2020-10-04 19:32:23 +00:00
|
|
|
return tolower(c);
|
2020-09-29 17:23:12 +00:00
|
|
|
}
|
2020-09-30 20:24:59 +00:00
|
|
|
|
2020-09-30 18:31:17 +00:00
|
|
|
////////////////////////
|
2020-10-03 11:03:18 +00:00
|
|
|
// /////////
|
|
|
|
// /////// ///////
|
|
|
|
// //////// ///////
|
|
|
|
// //////// ///////
|
|
|
|
// ////// ////////
|
|
|
|
// //// //////////
|
|
|
|
// /////////////
|
2020-09-30 18:31:17 +00:00
|
|
|
// /// ///////////
|
|
|
|
// //// //////////
|
|
|
|
// ///// /////////
|
|
|
|
// ////// ////////
|
|
|
|
// /////// ///////
|
|
|
|
////////////////////////
|