usaa20/cv1/program.c
2020-10-04 21:54:55 +02:00

97 lines
2.3 KiB
C

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#define LINESIZE 100
#define LINE_SIZE 100
#define POCET_JEDAL 100
struct pizza {
float prize;
char name[LINESIZE];
};
int read_pizza(struct pizza* item);
char hacker_script(char c);
int main(){
struct pizza jedalny_listok[POCET_JEDAL];
memset(jedalny_listok, 0,sizeof(struct pizza)*POCET_JEDAL);
char line[LINE_SIZE];
memset(line,0,LINE_SIZE);
printf("Zadaj hladanu surovinu:\n");
char* r = fgets(line,LINE_SIZE,stdin);
if(r != NULL && line[1] != 0){
printf("Zadaj jedalny listok\n");
struct pizza item;
int counter = 1;
while(read_pizza(&item)){
strcpy(jedalny_listok[counter-1].name, item.name);
jedalny_listok[counter-1].prize=item.prize;
counter += 1;
}
}
}
int search_string(const char* heap, const char* needle){
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(hacker_script(heap[i+j])!=hacker_script(needle[j])){
break;
}
if(j==M){
return i;
}
else{
return -1;
}
}
}
}
int read_pizza(struct pizza* item){
char line[LINE_SIZE];
memset(line,0,LINE_SIZE);
char* r = fgets(line,LINE_SIZE,stdin);
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);
if (value == 0.0F){
return 0;
}
item->prize = value;
strcpy(item->name, line);
return 1;
}
}
char hacker_script(char c){
char numbers[] = "0123456789";
char letters[] = "oizeasbtbq";
for (int i = 0; i < 10; i++){
if (c == numbers[i]){
return letters[i];
}
}
return tolower(c);
}
////////////////////////
// /////////
// /////// ///////
// //////// ///////
// //////// ///////
// ////// ////////
// //// //////////
// /////////////
// /// ///////////
// //// //////////
// ///// /////////
// ////// ////////
// /////// ///////
////////////////////////