107 lines
1.9 KiB
C
107 lines
1.9 KiB
C
#include<stdio.h>
|
|
#include<stdlib.h>
|
|
#include<string.h>
|
|
#include<ctype.h>
|
|
#define SIZE 100
|
|
|
|
struct pizza{
|
|
float price;
|
|
char name[SIZE];
|
|
};
|
|
|
|
|
|
char hacker_script(char c);
|
|
int read_pizza(struct pizza* pizza1);
|
|
int search(char *needle, char* heap);
|
|
char* upgrade_string(char* param);
|
|
|
|
int main(){
|
|
puts("Zadaj hladanu surovinu:");
|
|
char needle[SIZE];
|
|
memset(needle,0,SIZE);
|
|
fgets(needle,SIZE,stdin);
|
|
needle[strlen(needle)-1]='\0';
|
|
|
|
struct pizza list[30];
|
|
int index =0;
|
|
puts("Zadaj jedalny listok:");
|
|
while(read_pizza(&list[index])){
|
|
index++;
|
|
}
|
|
|
|
for(int i =0;i<index;i++){
|
|
if(search(needle,list[i].name)){
|
|
printf("%s\n%.2f\n",list[i].name,list[i].price);
|
|
}
|
|
|
|
}
|
|
printf("Nacitanych %d poloziek.\n",index);
|
|
return 0;
|
|
}
|
|
|
|
|
|
int read_pizza(struct pizza* pizza1){
|
|
if(fgets(pizza1->name,SIZE,stdin)==NULL)return 0;
|
|
if(pizza1->name[0]=='\n'){
|
|
return 0;
|
|
}
|
|
pizza1->name[strlen(pizza1->name)-1]='\0';
|
|
|
|
char* price = calloc(SIZE,sizeof(char));
|
|
fgets(price,SIZE,stdin);
|
|
price[strlen(price)-1]='\0';
|
|
|
|
sscanf(price,"%f",&(pizza1->price));
|
|
return 1;
|
|
}
|
|
|
|
|
|
char hacker_script(char c){
|
|
char numbers[] = "0123456789";
|
|
char letters[] = "oizeasbtbq";
|
|
int i;
|
|
for (i = 0; i < 10; i++){
|
|
if (c == numbers[i]){
|
|
return letters[i];
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
int search(char *needle,char *heap){
|
|
char* Needle = upgrade_string(needle);
|
|
char* Heap = upgrade_string(heap);
|
|
|
|
int M = strlen(Needle);
|
|
int N = strlen(Heap);
|
|
for(int i =0;i<=N-M;i++){
|
|
int j;
|
|
for(j=0;j<M;j++){
|
|
if(Heap[i+j]!=Needle[j]){
|
|
break;
|
|
}
|
|
}
|
|
if(j==M){
|
|
return 1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
char* upgrade_string(char* param){
|
|
char *str = (char*)malloc(strlen(param)*sizeof(char));
|
|
memset(str,0,SIZE);
|
|
strcpy(str,param);
|
|
for(int i =0;i<strlen(param);i++){
|
|
if(isdigit(str[i])){
|
|
str[i] = hacker_script(str[i]);
|
|
}else if(isupper(str[i])){
|
|
str[i] = tolower(str[i]);
|
|
}
|
|
|
|
}
|
|
|
|
return str;
|
|
}
|