usaa24/cv1/program.c

66 lines
1.6 KiB
C

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX_DISHES 100
#define MAX_LENGTH 100
void decode(char *text) {
for (int i = 0; text[i] != '\0'; 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;
}
text[i] = tolower(text[i]);
}
}
int main() {
char slovo[MAX_LENGTH];
char dish_name[MAX_LENGTH];
char price[MAX_LENGTH];
int count = 0;
printf("Zadaj hladanu surovinu:\n");
fgets(slovo, MAX_LENGTH, stdin);
slovo[strcspn(slovo, "\n")] = 0;
decode(slovo);
printf("Zadaj jedalny listok:\n");
while (1) {
if (fgets(dish_name, MAX_LENGTH, stdin) == NULL || strcmp(dish_name, "\n") == 0) {
break;
}
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);
return 0;
}