86 lines
2.0 KiB
C
86 lines
2.0 KiB
C
#include <stdio.h>
|
|
#include <stdio.h>
|
|
#include <ctype.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <math.h>
|
|
|
|
#define velkost strlen
|
|
#define size 100
|
|
|
|
void hacker_script(char *string, int len);
|
|
|
|
struct pizza {
|
|
char name[size];
|
|
float price;
|
|
};
|
|
|
|
int main() {
|
|
|
|
struct pizza listok[size];
|
|
char input[100]= {0};
|
|
char keyword[size] = {0};
|
|
char kopia[size] = {0};
|
|
int pomocna[size] = {0};
|
|
float cena = 0;
|
|
int counter = 0;
|
|
int helper = 2;
|
|
int yes = 0;
|
|
int y = 0;
|
|
char * pch;
|
|
|
|
|
|
printf("Zadaj hladanu surovinu:\n");
|
|
fgets(keyword, sizeof(keyword), stdin);
|
|
keyword[velkost(keyword)-1] = '\0';
|
|
hacker_script(keyword, strlen(keyword));
|
|
printf("Zadaj jedalny listok:\n");
|
|
while(fgets(input, sizeof(input), stdin) && strcmp( input, "\n" ) != 0 ){
|
|
if(helper %2 == 0){
|
|
strcpy(listok[counter].name, input);
|
|
yes++;
|
|
}
|
|
else{
|
|
cena = strtof(input, NULL);
|
|
listok[counter].price = cena;
|
|
yes++;
|
|
}
|
|
if(yes == 2){
|
|
counter++;
|
|
yes = 0;
|
|
}
|
|
helper++;
|
|
}
|
|
|
|
for(int x=0; x<counter; x++){
|
|
strcpy(kopia, listok[x].name);
|
|
hacker_script(kopia, strlen(kopia));
|
|
pch = strstr(kopia, keyword);
|
|
if(pch != NULL){
|
|
pomocna[y] = x;
|
|
y++;
|
|
}
|
|
}
|
|
|
|
for(int z=0; z<y; z++){
|
|
printf("%s",listok[pomocna[z]].name);
|
|
printf("%.2f \n",listok[pomocna[z]].price);
|
|
}
|
|
printf("Nacitanych %d poloziek.\n",(helper-2)/2);
|
|
|
|
}
|
|
|
|
void hacker_script(char *string, int len){
|
|
char letters[] = "oizeasbtbq";
|
|
for (int i = 0; i < len; i++) {
|
|
string[i] = (char)tolower(string[i]);
|
|
if (isdigit(string[i])) {
|
|
for (int j = 0; j < 10; j++) {
|
|
if (string[i] == (char)j+'0') {
|
|
string[i] = letters[j];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |