2020-09-29 20:40:24 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#define LINESIZE 100
|
|
|
|
struct pizza{
|
|
|
|
char name[LINESIZE];
|
|
|
|
float prize;
|
|
|
|
};
|
|
|
|
|
|
|
|
int read_pizza(struct pizza* item){
|
|
|
|
|
|
|
|
char line1[LINESIZE];
|
|
|
|
char line2[LINESIZE];
|
|
|
|
|
|
|
|
memset(line1, 0, LINESIZE);
|
|
|
|
memset(line2, 0, LINESIZE);
|
|
|
|
char *l1 = fgets(line1,LINESIZE,stdin);
|
|
|
|
char *l2 = fgets(line2,LINESIZE,stdin);
|
|
|
|
float value = strtof(line2, &l2);
|
|
|
|
if(value == 0.0F){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(l1 != NULL && line1[1] != 0){
|
|
|
|
item->prize = value;
|
|
|
|
strcpy(item->name, line1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int search_string(const char* heap, const char* needle){
|
2020-10-26 11:21:05 +00:00
|
|
|
|
2020-09-29 20:40:24 +00:00
|
|
|
int H = strlen(heap);
|
|
|
|
int N = strlen(needle);
|
2020-10-26 11:21:05 +00:00
|
|
|
int i = 0;
|
2020-09-29 20:40:24 +00:00
|
|
|
for(i = 0; i <= H - N; i++){
|
|
|
|
int j;
|
2020-10-26 11:21:05 +00:00
|
|
|
|
2020-09-29 20:40:24 +00:00
|
|
|
for(j = 0; j < N; j++){
|
|
|
|
if(heap[i+j] != needle[j]){
|
2020-10-26 11:21:05 +00:00
|
|
|
break;
|
2020-09-29 20:40:24 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-26 11:21:05 +00:00
|
|
|
if(j == N){
|
|
|
|
return i;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
2020-09-29 20:40:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-26 11:21:05 +00:00
|
|
|
|
2020-09-29 20:40:24 +00:00
|
|
|
char hacker_script(char c){
|
|
|
|
if(isupper(c)){
|
2020-10-26 11:21:05 +00:00
|
|
|
c = tolower(c);
|
|
|
|
}
|
2020-09-29 20:40:24 +00:00
|
|
|
char numbers[] = "0123456789";
|
|
|
|
char letters[] = "oizeasbtbq";
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 10; i++){
|
|
|
|
if (c == numbers[i]){
|
|
|
|
c = letters[i];
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
}
|
2020-10-26 11:21:05 +00:00
|
|
|
return c;
|
2020-09-29 20:40:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-26 11:21:05 +00:00
|
|
|
|
2020-09-29 20:40:24 +00:00
|
|
|
int main(){
|
2020-09-29 20:54:46 +00:00
|
|
|
|
|
|
|
printf("Zadaj hladanu surovinu:");
|
2020-09-29 20:40:24 +00:00
|
|
|
char key[LINESIZE];
|
|
|
|
memset(key,0,LINESIZE);
|
2020-10-26 11:21:05 +00:00
|
|
|
char* r = fgets(key,LINESIZE,stdin);
|
|
|
|
key[strlen(key)-1] = '\0';
|
|
|
|
int k = 0;
|
|
|
|
for(k = 0; k < strlen(key); k++){
|
|
|
|
key[k] = hacker_script(key[k]);
|
|
|
|
}
|
|
|
|
|
2020-09-29 20:54:46 +00:00
|
|
|
printf("Zadaj jedalny listok:");
|
2020-09-29 20:40:24 +00:00
|
|
|
struct pizza jedalny_listok[100];
|
|
|
|
struct pizza pomocny[100];
|
|
|
|
memset(pomocny, 0, sizeof(struct pizza)*100);
|
2020-10-26 11:21:05 +00:00
|
|
|
memset(jedalny_listok, 0,sizeof(struct pizza)*100);
|
2020-09-29 20:40:24 +00:00
|
|
|
struct pizza item;
|
|
|
|
int counter = 0;
|
2020-10-26 11:21:05 +00:00
|
|
|
|
2020-09-29 20:54:46 +00:00
|
|
|
|
2020-09-29 20:40:24 +00:00
|
|
|
|
2020-10-26 11:21:05 +00:00
|
|
|
while(stdin,read_pizza(&item)){
|
2020-09-29 20:40:24 +00:00
|
|
|
strcpy(jedalny_listok[counter].name, item.name);
|
|
|
|
jedalny_listok[counter].prize = item.prize;
|
|
|
|
counter++;
|
|
|
|
}
|
2020-10-26 11:21:05 +00:00
|
|
|
|
2020-09-29 20:40:24 +00:00
|
|
|
int i, j, f;
|
2020-10-26 11:21:05 +00:00
|
|
|
int i, j;
|
2020-09-29 20:40:24 +00:00
|
|
|
for(i = 0; i < counter; i++){
|
|
|
|
for(j = 0; j < strlen(jedalny_listok[i].name); j++){
|
|
|
|
pomocny[i].name[j] = hacker_script(jedalny_listok[i].name[j]);
|
2020-10-26 11:21:05 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
int result = search_string(pomocny[i].name, key);
|
|
|
|
if(result != -1){
|
2020-09-29 20:40:24 +00:00
|
|
|
printf("%s", jedalny_listok[i].name);
|
|
|
|
printf("%.2f\n", jedalny_listok[i].prize);
|
2020-10-26 11:21:05 +00:00
|
|
|
}
|
|
|
|
|
2020-09-29 20:40:24 +00:00
|
|
|
}
|
2020-10-26 11:21:05 +00:00
|
|
|
printf("Nacitanych %d poloziek.\n", counter);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
2020-09-29 20:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|