program.c
This commit is contained in:
parent
a138eedb1c
commit
f387a2a3a6
141
cv1/program.c
141
cv1/program.c
@ -1,110 +1,117 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <ctype.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;
|
||||||
|
}
|
||||||
|
|
||||||
#define MAX_ITEMS 100
|
|
||||||
#define MAX_NAME_LENGTH 100
|
|
||||||
|
|
||||||
char hacker_script(char c) {
|
char hacker_script(char c) {
|
||||||
|
|
||||||
char numbers[] = "0123456789";
|
char numbers[] = "0123456789";
|
||||||
char letters[] = "oizeasbtbq";
|
char letters[] = "oizeasbtbq";
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
if (c == numbers[i]) {
|
if (c == numbers[i]) {
|
||||||
return letters[i];
|
return letters[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return tolower(c);
|
||||||
if(isupper(c)){
|
|
||||||
return tolower(c);
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int search_string(const char* aber, const char* b) {
|
int search(const char* pop, const char* rar) {
|
||||||
int aber_l = strlen(aber);
|
int A = strlen(rar);
|
||||||
int b_l = strlen(b);
|
int B = strlen(pop);
|
||||||
|
for (int i = 0; i <= B - A; i++) {
|
||||||
for (int i = 0; i <= aber_l - b_l; i++) {
|
|
||||||
int j;
|
int j;
|
||||||
for (j = 0; j < b_l; j++) {
|
|
||||||
if (hacker_script(aber[i + j]) != hacker_script(aber[j])) {
|
for (j = 0; j < A; j++) {
|
||||||
|
if (hacker_script(pop[i + j]) != hacker_script(rar[j])) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (j == b_l) {
|
if (j == A) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct menu {
|
|
||||||
char name[MAX_NAME_LENGTH];
|
|
||||||
float price;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
int read_pizza(struct pizza* item) {
|
||||||
int read_pizza(struct menu* pizza) {
|
|
||||||
char line[MAX_NAME_LENGTH];
|
|
||||||
char line2[MAX_NAME_LENGTH];
|
|
||||||
|
|
||||||
if (fgets(line, sizeof(line), stdin) == NULL) {
|
char line[LINE_SIZE];
|
||||||
return 0;
|
memset(line, 0, LINE_SIZE);
|
||||||
}
|
|
||||||
line[strcspn(line, "\n")] = '\0';
|
|
||||||
|
|
||||||
if (fgets(line2, sizeof(line2), stdin) == NULL) {
|
char* r = fgets(line, LINE_SIZE, stdin);
|
||||||
return 0; // Failed to read price
|
delet(line);
|
||||||
}
|
|
||||||
line2[strcspn(line2, "\n")] = '\0';
|
|
||||||
|
|
||||||
float value = strtof(line2, NULL);
|
if (r != NULL && line[1] != 0) {
|
||||||
if (value == 0.0F) {
|
|
||||||
return 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;
|
||||||
pizza->price = value;
|
|
||||||
strcpy(pizza->name, line);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char searchStr[MAX_NAME_LENGTH];
|
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");
|
printf("Zadaj hladanu surovinu:\n");
|
||||||
if (fgets(searchStr, sizeof(searchStr), stdin) == NULL) {
|
if (fgets(search_str, sizeof(search_str), stdin) == NULL) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
searchStr[strcspn(searchStr, "\n")] = '\0';
|
|
||||||
|
|
||||||
struct menu* menu = malloc(MAX_ITEMS * sizeof(struct menu));
|
delet(search_str);
|
||||||
if (menu == NULL) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int itemCount = 0;
|
|
||||||
|
|
||||||
printf("Zadaj jedalny listok:\n");
|
printf("Zadaj jedalny listok:\n");
|
||||||
while (itemCount < MAX_ITEMS) {
|
|
||||||
struct menu pizza;
|
struct pizza item;
|
||||||
if (!read_pizza(&pizza)) {
|
|
||||||
break;
|
while (item_count < MAX_MENU_ITEMS && read_pizza(&item)) {
|
||||||
}
|
strcpy(menu[item_count].name, item.name);
|
||||||
|
menu[item_count].price = item.price;
|
||||||
|
item_count++;
|
||||||
if (search_string(pizza.name, searchStr) != -1) {
|
|
||||||
printf("%s\n", pizza.name);
|
|
||||||
printf("%.2f\n", pizza.price);
|
|
||||||
}
|
|
||||||
|
|
||||||
itemCount++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(menu);
|
for (int i = 0; i < item_count; i++) {
|
||||||
printf("Nacitanych %d poloziek.\n", itemCount);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user