Обновить cv1/program.c
This commit is contained in:
parent
b000a8bb3b
commit
d730335393
@ -2,60 +2,64 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
void normalize(char *str) {
|
#define MAX_DISHES 100
|
||||||
for (int i = 0; str[i] != '\0'; i++) {
|
#define MAX_LENGTH 100
|
||||||
switch (str[i]) {
|
|
||||||
case '0': str[i] = 'o'; break;
|
|
||||||
case '1': str[i] = 'i'; break;
|
void decode(char *text) {
|
||||||
case '2': str[i] = 'z'; break;
|
for (int i = 0; text[i] != '\0'; i++) {
|
||||||
case '3': str[i] = 'e'; break;
|
|
||||||
case '4': str[i] = 'a'; break;
|
switch (text[i]) {
|
||||||
case '5': str[i] = 's'; break;
|
case '0': text[i] = 'o'; break;
|
||||||
case '6': str[i] = 'b'; break;
|
case '1': text[i] = 'i'; break;
|
||||||
case '7': str[i] = 't'; break;
|
case '2': text[i] = 'z'; break;
|
||||||
case '8': str[i] = 'b'; break;
|
case '3': text[i] = 'e'; break;
|
||||||
case '9': str[i] = 'q'; break;
|
case '4': text[i] = 'a'; break;
|
||||||
default: str[i] = tolower(str[i]); break;
|
case '5': text[i] = 's'; break;
|
||||||
|
case '6': text[i] = 'b'; break;
|
||||||
|
case '7': text[i] = 't'; break;
|
||||||
|
case '8': text[i] = 'b'; break;
|
||||||
|
case '9': text[i] = 'q'; break;
|
||||||
}
|
}
|
||||||
|
text[i] = tolower(text[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char search[100];
|
char slovo[MAX_LENGTH];
|
||||||
char item_name[100];
|
char dish_name[MAX_LENGTH];
|
||||||
char price[10];
|
char price[MAX_LENGTH];
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
|
|
||||||
printf("Zadaj hladanu surovinu:");
|
printf("Zadaj hladanu surovinu:\n");
|
||||||
fgets(search, sizeof(search), stdin);
|
fgets(slovo, MAX_LENGTH, stdin);
|
||||||
search[strcspn(search, "\n")] = '\0';
|
slovo[strcspn(slovo, "\n")] = 0;
|
||||||
normalize(search);
|
decode(slovo);
|
||||||
|
|
||||||
printf("Zadaj jedalny listok:\n");
|
printf("Zadaj jedalny listok:\n");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
if (fgets(dish_name, MAX_LENGTH, stdin) == NULL || strcmp(dish_name, "\n") == 0) {
|
||||||
fgets(item_name, sizeof(item_name), stdin);
|
break;
|
||||||
item_name[strcspn(item_name, "\n")] = '\0';
|
|
||||||
if (strlen(item_name) == 0) break;
|
|
||||||
|
|
||||||
|
|
||||||
fgets(price, sizeof(price), stdin);
|
|
||||||
price[strcspn(price, "\n")] = '\0';
|
|
||||||
count++;
|
|
||||||
|
|
||||||
char normalized_name[100];
|
|
||||||
strcpy(normalized_name, item_name);
|
|
||||||
normalize(normalized_name);
|
|
||||||
|
|
||||||
if (strstr(normalized_name, search) != NULL) {
|
|
||||||
printf("%s\n%s\n", item_name, price);
|
|
||||||
}
|
}
|
||||||
|
dish_name[strcspn(dish_name, "\n")] = 0;
|
||||||
|
// Načítanie ceny jedla
|
||||||
|
if (fgets(price, MAX_LENGTH, stdin) == NULL || strcmp(price, "\n") == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
price[strcspn(price, "\n")] = 0;
|
||||||
|
|
||||||
|
char normal_dish[MAX_LENGTH];
|
||||||
|
strcpy(normal_dish, dish_name);
|
||||||
|
decode(normal_dish);
|
||||||
|
if (strstr(normal_dish, slovo) != NULL) {
|
||||||
|
printf("%s\n%s\n", dish_name, price);
|
||||||
|
}
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
printf("Nacitanych %d poloziek.\n", count);
|
printf("Nacitanych %d poloziek.\n", count);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user