program.c
This commit is contained in:
parent
4903b66204
commit
fe7aa3af31
120
cv1/program.c
120
cv1/program.c
@ -10,100 +10,64 @@ struct Menu{
|
|||||||
float price;
|
float price;
|
||||||
};
|
};
|
||||||
|
|
||||||
int lower(char c) {
|
void transform(char *str) {
|
||||||
return (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9');
|
for (int i = 0; str[i]; i++) {
|
||||||
}
|
switch (str[i]) {
|
||||||
|
case '0': str[i] = 'o'; break;
|
||||||
char transform(char c) {
|
case '1': str[i] = 'i'; break;
|
||||||
switch (c) {
|
case '2': str[i] = 'z'; break;
|
||||||
case '0': return 'o';
|
case '3': str[i] = 'e'; break;
|
||||||
case '1': return 'i';
|
case '4': str[i] = 'a'; break;
|
||||||
case '2': return 'z';
|
case '5': str[i] = 's'; break;
|
||||||
case '3': return 'e';
|
case '6': str[i] = 'b'; break;
|
||||||
case '4': return 'a';
|
case '7': str[i] = 't'; break;
|
||||||
case '5': return 's';
|
case '8': str[i] = 'b'; break;
|
||||||
case '6': return 'b';
|
case '9': str[i] = 'q'; break;
|
||||||
case '7': return 't';
|
default: break;
|
||||||
case '8': return 'b';
|
|
||||||
case '9': return 'q';
|
|
||||||
default: return c;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int compare(const char *str1, const char *str2) {
|
|
||||||
int i = 0, j = 0;
|
|
||||||
while (str1[i] && str2[j]) {
|
|
||||||
char c1 = transform(str1[i]);
|
|
||||||
char c2 = transform(str2[j]);
|
|
||||||
|
|
||||||
if (str1[i] >= 'A' && str1[i] <= 'Z') {
|
|
||||||
str1[i] += 'a' - 'A';
|
|
||||||
}
|
}
|
||||||
if (str2[i]>= 'A' && str2[i] <= 'Z') {
|
|
||||||
str2[i] += 'a' - 'A';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c1 != c2) {
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
return str1[i] == '\0' && str2[j] == '\0'; // Strings are equal
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char searchStr[100];
|
char search[100];
|
||||||
printf("Zadaj hladanu surovinu: ");
|
int pizza = 0;
|
||||||
if (fgets(searchStr, sizeof(searchStr), stdin) == NULL) {
|
|
||||||
printf("Chyba pri citani vstupu.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t len = strlen(searchStr);
|
printf("Zadaj hladanu surovinu:\n");
|
||||||
if (len > 0 && searchStr[len - 1] == '\n') {
|
fgets(searchStr, sizeof(searchStr), stdin);
|
||||||
searchStr[len - 1] = '\0';
|
search[strlen(search) - 1] = '\0';
|
||||||
}
|
|
||||||
|
|
||||||
struct MenuItem menu[100];
|
transform(search);
|
||||||
int menuSize = 0;
|
|
||||||
|
|
||||||
printf("Zadaj jedalny listok:\n");
|
printf("Zadaj jedalny listok:\n");
|
||||||
|
|
||||||
while (menuSize < 100) {
|
while (1) {
|
||||||
if (fgets(menu[menuSize].name, sizeof(menu[menuSize].name), stdin) == NULL) {
|
struct Menu menu;
|
||||||
|
char pizza_name[100];
|
||||||
|
|
||||||
|
if (fgets(pizza_name, sizeof(pizza_name), stdin) == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (sscanf(menu[menuSize].name, "%f", &menu[menuSize].price) != 1) {
|
|
||||||
printf("Chyba pri citani ceny.\n");
|
pizza_name[strlen(pizza_name) - 1] = '\0';
|
||||||
|
|
||||||
|
char transformed_pizza_name[100];
|
||||||
|
strcpy(transformedpizza_name, pizza_name);
|
||||||
|
transform(transformed_pizza_name);
|
||||||
|
|
||||||
|
if (strstr(transformed_pizza_name, search) != NULL) {
|
||||||
|
// Načítanie ceny jedla
|
||||||
|
if (scanf("%f", &pizza.price) != 1) {
|
||||||
|
printf("Chyba pri nacitani ceny pre jedlo: %s\n", pizza_name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
menuSize++;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\nNájdené položky:\n");
|
printf("%s\n", pizza_name);
|
||||||
int foundItems = 0;
|
printf("%.2f\n", pizza.price);
|
||||||
for (int i = 0; i < menuSize; i++) {
|
item++;
|
||||||
if (strstr(menu[i].name, searchStr) || compareStrings(menu[i].name, searchStr)) {
|
|
||||||
printf("%s\n%.2f\n", menu[i].name, menu[i].price);
|
|
||||||
foundItems++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\nNacitanych %d poloziek.\n", menuSize);
|
printf("Nacitanych %d poloziek.\n", item);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user