74 lines
2.0 KiB
C
74 lines
2.0 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
#define MAX_DISHES 100
|
|
#define MAX_NAME_LEN 100
|
|
void decodovane_slovo(char *text) {
|
|
for (int i = 0; text[i]; i++) {
|
|
switch (text[i]) {
|
|
case '0': text[i] = 'o'; break;
|
|
case '1': text[i] = 'i'; break;
|
|
case '2': text[i] = 'z'; break;
|
|
case '3': text[i] = 'e'; break;
|
|
case '4': text[i] = 'a'; 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;
|
|
default: text[i] = tolower(text[i]); break;
|
|
}
|
|
}
|
|
}
|
|
int main() {
|
|
char ingredient[MAX_NAME_LEN];
|
|
char dishes[MAX_DISHES][2][MAX_NAME_LEN];
|
|
int count = 0;
|
|
|
|
printf("Zadaj hladanu surovinu:");
|
|
if (fgets(ingredient, MAX_NAME_LEN, stdin) == NULL) {
|
|
return 0;
|
|
}
|
|
|
|
|
|
printf("Zadaj jedalny listok:");
|
|
while (1) {
|
|
char name[MAX_NAME_LEN], price[MAX_NAME_LEN];
|
|
|
|
if (fgets(name, MAX_NAME_LEN, stdin) == NULL) {
|
|
return 0;
|
|
}
|
|
|
|
if (strlen(name) == 0) {
|
|
break;
|
|
}
|
|
if (fgets(price, MAX_NAME_LEN, stdin) == NULL) {
|
|
return 0;
|
|
}
|
|
|
|
strncpy(dishes[count][0], name, MAX_NAME_LEN - 1);
|
|
dishes[count][0][MAX_NAME_LEN - 1] = '\0';
|
|
|
|
strncpy(dishes[count][1], price, MAX_NAME_LEN - 1);
|
|
dishes[count][1][MAX_NAME_LEN - 1] = '\0';
|
|
|
|
count++;
|
|
}
|
|
decodovane_slovo(ingredient);
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
char decoded_name[MAX_NAME_LEN];
|
|
strncpy(decoded_name, dishes[i][0], MAX_NAME_LEN - 1);
|
|
decoded_name[MAX_NAME_LEN - 1] = '\0';
|
|
|
|
decodovane_slovo(decoded_name);
|
|
|
|
if (strstr(decoded_name, ingredient) != NULL) {
|
|
printf("%s%s", dishes[i][0], dishes[i][1]);
|
|
|
|
}
|
|
}
|
|
printf("Nacitanych %d poloziek.", count);
|
|
return 0;
|
|
}
|