program.c
This commit is contained in:
parent
851dda9ff8
commit
5fd67120ee
106
cv1/program.c
106
cv1/program.c
@ -1,31 +1,74 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define MAX_ITEMS 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 {
|
||||
char name[MAX_NAME_LENGTH];
|
||||
float price;
|
||||
};
|
||||
|
||||
void transform(char *str) {
|
||||
for (int i = 0; str[i]; i++) {
|
||||
switch (str[i]) {
|
||||
case '0': str[i] = 'o'; break;
|
||||
case '1': str[i] = 'i'; break;
|
||||
case '2': str[i] = 'z'; break;
|
||||
case '3': str[i] = 'e'; break;
|
||||
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;
|
||||
}
|
||||
|
||||
int read_pizza(struct menu* pizza) {
|
||||
char line[MAX_NAME_LENGTH];
|
||||
char line2[MAX_NAME_LENGTH];
|
||||
|
||||
if (fgets(line, sizeof(line), stdin) == NULL) {
|
||||
return 0;
|
||||
}
|
||||
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() {
|
||||
@ -34,37 +77,32 @@ int main() {
|
||||
if (fgets(searchStr, sizeof(searchStr), stdin) == NULL) {
|
||||
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;
|
||||
|
||||
printf("Zadaj jedalny listok:\n");
|
||||
while (itemCount < MAX_ITEMS) {
|
||||
char pizza_name[MAX_NAME_LENGTH];
|
||||
if (fgets(pizza_name, sizeof(pizza_name), stdin) == NULL) {
|
||||
break; // Koniec vstupu
|
||||
struct menu pizza;
|
||||
if (!read_pizza(&pizza)) {
|
||||
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 (strstr(pizza_name, searchStr) != NULL) {
|
||||
printf("%s\n", pizza_name);
|
||||
printf("%.2f\n", itemPrice);
|
||||
|
||||
if (search_string(pizza.name, searchStr) != -1) {
|
||||
printf("%s\n", pizza.name);
|
||||
printf("%.2f\n", pizza.price);
|
||||
}
|
||||
|
||||
itemCount++;
|
||||
}
|
||||
|
||||
free(menu);
|
||||
printf("Nacitanych %d poloziek.\n", itemCount);
|
||||
|
||||
return 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user