This commit is contained in:
Peter Petrek 2021-10-08 01:16:59 +02:00
parent 2493c2e634
commit 34be285963
3 changed files with 74 additions and 4 deletions

11
cv1/Makefile Normal file
View File

@ -0,0 +1,11 @@
# variables
CC=gcc
CFLAGS=-std=c11 -Wall -Werror
LDLIBS=-lm
OUTPUT=$@
# targets
%: %.c
$(CC) $(CFLAGS) $@.c $(LDLIBS) -o $(OUTPUT)

Binary file not shown.

View File

@ -5,10 +5,13 @@
#include <stdlib.h>
#include <math.h>
#define velkost strlen
#define size 100
void hacker_script(char *string, int len);
struct pizza {
char meno[size];
char name[size];
float price;
};
@ -17,11 +20,67 @@ int main() {
struct pizza listok[size];
char input[100]= {0};
char keyword[size] = {0};
printf("Zadaj hladanu surovinu:");
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++;
}
printf("%s", keyword);
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.",(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;
}
}
}
}
}