program.c
This commit is contained in:
parent
851dda9ff8
commit
5fd67120ee
104
cv1/program.c
104
cv1/program.c
@ -1,31 +1,74 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#define MAX_ITEMS 100
|
#define MAX_ITEMS 100
|
||||||
#define MAX_NAME_LENGTH 100
|
#define MAX_NAME_LENGTH 100
|
||||||
|
|
||||||
|
char hacker_script(char c) {
|
||||||
|
|
||||||
|
if (isupper(c)) {
|
||||||
|
c = tolower(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
char numbers[] = "0123456789";
|
||||||
|
char letters[] = "oizeasbtbq";
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
if (c == numbers[i]) {
|
||||||
|
return letters[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int search_string(const char* aber, const char* b) {
|
||||||
|
int aber_l = strlen(aber);
|
||||||
|
int b_l = strlen(b);
|
||||||
|
|
||||||
|
for (int i = 0; i <= aber_l - b_l; i++) {
|
||||||
|
int j;
|
||||||
|
for (j = 0; j < b_l; j++) {
|
||||||
|
if (hacker_script(aber[i + j]) != hacker_script(aber[j])) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (j == b_l) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
struct menu {
|
struct menu {
|
||||||
char name[MAX_NAME_LENGTH];
|
char name[MAX_NAME_LENGTH];
|
||||||
float price;
|
float price;
|
||||||
};
|
};
|
||||||
|
|
||||||
void transform(char *str) {
|
|
||||||
for (int i = 0; str[i]; i++) {
|
int read_pizza(struct menu* pizza) {
|
||||||
switch (str[i]) {
|
char line[MAX_NAME_LENGTH];
|
||||||
case '0': str[i] = 'o'; break;
|
char line2[MAX_NAME_LENGTH];
|
||||||
case '1': str[i] = 'i'; break;
|
|
||||||
case '2': str[i] = 'z'; break;
|
if (fgets(line, sizeof(line), stdin) == NULL) {
|
||||||
case '3': str[i] = 'e'; break;
|
return 0;
|
||||||
case '4': str[i] = 'a'; break;
|
|
||||||
case '5': str[i] = 's'; break;
|
|
||||||
case '6': str[i] = 'b'; break;
|
|
||||||
case '7': str[i] = 't'; break;
|
|
||||||
case '8': str[i] = 'b'; break;
|
|
||||||
case '9': str[i] = 'q'; break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
line[strcspn(line, "\n")] = '\0';
|
||||||
|
|
||||||
|
if (fgets(line2, sizeof(line2), stdin) == NULL) {
|
||||||
|
return 0; // Failed to read price
|
||||||
|
}
|
||||||
|
line2[strcspn(line2, "\n")] = '\0';
|
||||||
|
|
||||||
|
float value = strtof(line2, NULL);
|
||||||
|
if (value == 0.0F) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pizza->price = value;
|
||||||
|
strcpy(pizza->name, line);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@ -34,37 +77,32 @@ int main() {
|
|||||||
if (fgets(searchStr, sizeof(searchStr), stdin) == NULL) {
|
if (fgets(searchStr, sizeof(searchStr), stdin) == NULL) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
searchStr[strcspn(searchStr, "\n")] = '\0'; // Odstrániť znak nového riadku
|
searchStr[strcspn(searchStr, "\n")] = '\0';
|
||||||
|
|
||||||
|
struct menu* menu = malloc(MAX_ITEMS * sizeof(struct menu));
|
||||||
|
if (menu == NULL) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
struct menu menu[MAX_ITEMS];
|
|
||||||
int itemCount = 0;
|
int itemCount = 0;
|
||||||
|
|
||||||
printf("Zadaj jedalny listok:\n");
|
printf("Zadaj jedalny listok:\n");
|
||||||
while (itemCount < MAX_ITEMS) {
|
while (itemCount < MAX_ITEMS) {
|
||||||
char pizza_name[MAX_NAME_LENGTH];
|
struct menu pizza;
|
||||||
if (fgets(pizza_name, sizeof(pizza_name), stdin) == NULL) {
|
if (!read_pizza(&pizza)) {
|
||||||
break; // Koniec vstupu
|
break;
|
||||||
}
|
}
|
||||||
pizza_name[strcspn(pizza_name, "\n")] = '\0'; // Odstrániť znak nového riadku
|
|
||||||
// Transformácia názvu jedla
|
|
||||||
transform(pizza_name);
|
|
||||||
|
|
||||||
// Načítanie ceny jedla
|
|
||||||
float itemPrice;
|
|
||||||
if (scanf("%f", &itemPrice) != 1) {
|
|
||||||
break; // Chybný vstup
|
|
||||||
}
|
|
||||||
getchar(); // Načítať znak nového riadku
|
|
||||||
|
|
||||||
// Skontrolujte, či názov obsahuje vyhľadávací reťazec
|
if (search_string(pizza.name, searchStr) != -1) {
|
||||||
if (strstr(pizza_name, searchStr) != NULL) {
|
printf("%s\n", pizza.name);
|
||||||
printf("%s\n", pizza_name);
|
printf("%.2f\n", pizza.price);
|
||||||
printf("%.2f\n", itemPrice);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
itemCount++;
|
itemCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(menu);
|
||||||
printf("Nacitanych %d poloziek.\n", itemCount);
|
printf("Nacitanych %d poloziek.\n", itemCount);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user