usaa24/cv1/program.c

94 lines
2.3 KiB
C

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX_DISHES 100
#define MAX_NAME_LENGTH 100
// Funkcia na prekonvertovanie textu do formátu Hacker script
void to_hacker_script(char *input, char *output) {
while (*input) {
switch (*input) {
case 'o':
case 'O':
*output++ = '0';
break;
case 'i':
case 'I':
*output++ = '1';
break;
case 'z':
case 'Z':
*output++ = '2';
break;
case 'e':
case 'E':
*output++ = '3';
break;
case 'a':
case 'A':
*output++ = '4';
break;
case 's':
case 'S':
*output++ = '5';
break;
case 'b':
case 'B':
*output++ = '6';
break;
case 't':
case 'T':
*output++ = '7';
break;
case 'q':
case 'Q':
*output++ = '9';
break;
case '8':
*output++ = '8';
break;
default:
*output++ = tolower(*input);
break;
}
input++;
}
*output = '\0';
}
int main() {
char search_term[MAX_NAME_LENGTH];
char dish_name[MAX_NAME_LENGTH];
char dish_price[MAX_NAME_LENGTH];
char hacker_search[MAX_NAME_LENGTH];
int count = 0;
printf("Zadaj hladanu surovinu: ");
scanf("%s", search_term);
// Prekonvertovanie hladanej suroviny do Hacker script
to_hacker_script(search_term, hacker_search);
printf("Zadaj jedalny listok:\n");
while (1) {
if (scanf("%s", dish_name) == EOF) {
break;
}
scanf("%s", dish_price);
// Vytvorenie prekonvertovanej názvu jedla
char hacker_dish_name[MAX_NAME_LENGTH];
to_hacker_script(dish_name, hacker_dish_name);
// Kontrola, či názov jedla obsahuje vyhľadávanú surovinu
if (strstr(hacker_dish_name, hacker_search) != NULL) {
printf("%s\n%s\n", dish_name, dish_price);
count++;
}
}
printf("Nacitanych %d poloziek.\n", count);
return 0;
}