usaa21/cv1/program.c

86 lines
2.0 KiB
C
Raw Normal View History

2021-10-07 14:43:50 +00:00
#include <stdio.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
2021-10-07 23:16:59 +00:00
#define velkost strlen
2021-10-07 14:43:50 +00:00
#define size 100
2021-10-07 23:16:59 +00:00
void hacker_script(char *string, int len);
2021-10-07 14:43:50 +00:00
struct pizza {
2021-10-07 23:16:59 +00:00
char name[size];
2021-10-07 14:43:50 +00:00
float price;
};
int main() {
struct pizza listok[size];
char input[100]= {0};
char keyword[size] = {0};
2021-10-07 23:16:59 +00:00
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;
2021-10-07 14:43:50 +00:00
2021-10-07 23:16:59 +00:00
printf("Zadaj hladanu surovinu:\n");
2021-10-07 14:43:50 +00:00
fgets(keyword, sizeof(keyword), stdin);
2021-10-07 23:16:59 +00:00
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.",(helper-2)/2);
2021-10-07 14:43:50 +00:00
2021-10-07 23:16:59 +00:00
}
2021-10-07 14:43:50 +00:00
2021-10-07 23:16:59 +00:00
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;
}
}
}
}
2021-10-07 14:43:50 +00:00
}