118 lines
2.3 KiB
C
118 lines
2.3 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
#include <stdlib.h>
|
|
|
|
#define LINE_SIZE 100
|
|
#define MAX_MENU_ITEMS 10
|
|
|
|
|
|
struct pizza {
|
|
float price;
|
|
char name[LINE_SIZE];
|
|
};
|
|
|
|
|
|
void delet(char* str) {
|
|
int i = 0;
|
|
while (str[i] != '\n' && str[i] != 0) {
|
|
i++;
|
|
}
|
|
str[i] = 0;
|
|
}
|
|
|
|
|
|
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);
|
|
}
|
|
|
|
|
|
int search(const char* pop, const char* rar) {
|
|
int A = strlen(rar);
|
|
int B = strlen(pop);
|
|
for (int i = 0; i <= B - A; i++) {
|
|
int j;
|
|
|
|
for (j = 0; j < A; j++) {
|
|
if (hacker_script(pop[i + j]) != hacker_script(rar[j])) {
|
|
break;
|
|
}
|
|
}
|
|
if (j == A) {
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
|
|
int read_pizza(struct pizza* item) {
|
|
|
|
char line[LINE_SIZE];
|
|
memset(line, 0, LINE_SIZE);
|
|
|
|
char* r = fgets(line, LINE_SIZE, stdin);
|
|
delet(line);
|
|
|
|
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->price = value;
|
|
strcpy(item->name, line);
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int main() {
|
|
struct pizza menu[MAX_MENU_ITEMS];
|
|
memset(menu, 0, sizeof(struct pizza) * MAX_MENU_ITEMS);
|
|
int item_count = 0;
|
|
char search_str[LINE_SIZE];
|
|
|
|
printf("Zadaj hladanu surovinu:\n");
|
|
if (fgets(search_str, sizeof(search_str), stdin) == NULL) {
|
|
return 1;
|
|
}
|
|
|
|
delet(search_str);
|
|
|
|
printf("Zadaj jedalny listok:\n");
|
|
|
|
struct pizza item;
|
|
|
|
while (item_count < MAX_MENU_ITEMS && read_pizza(&item)) {
|
|
strcpy(menu[item_count].name, item.name);
|
|
menu[item_count].price = item.price;
|
|
item_count++;
|
|
}
|
|
|
|
for (int i = 0; i < item_count; i++) {
|
|
if (search(menu[i].name, search_str) != -1) {
|
|
printf("%s\n", menu[i].name);
|
|
printf("%.2f\n", menu[i].price);
|
|
}
|
|
}
|
|
|
|
printf("Nacitanych %d poloziek.\n", item_count);
|
|
|
|
return 0;
|
|
}
|