usaa24/cv1/program.c

94 lines
2.3 KiB
C
Raw Normal View History

2024-10-03 21:16:54 +00:00
#include <stdio.h>
#include <string.h>
#include <ctype.h>
2024-10-03 21:02:43 +00:00
2024-10-04 12:28:10 +00:00
#define MAX_DISHES 100
#define MAX_NAME_LENGTH 100
2024-10-04 12:02:06 +00:00
2024-10-04 12:28:10 +00:00
// 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);
2024-10-03 21:16:54 +00:00
break;
}
2024-10-04 12:28:10 +00:00
input++;
2024-10-03 21:16:54 +00:00
}
2024-10-04 12:28:10 +00:00
*output = '\0';
2024-10-03 21:16:54 +00:00
}
2024-10-04 12:20:12 +00:00
int main() {
2024-10-04 12:28:10 +00:00
char search_term[MAX_NAME_LENGTH];
char dish_name[MAX_NAME_LENGTH];
char dish_price[MAX_NAME_LENGTH];
char hacker_search[MAX_NAME_LENGTH];
2024-10-04 12:02:06 +00:00
int count = 0;
2024-10-03 21:16:54 +00:00
2024-10-04 12:28:10 +00:00
printf("Zadaj hladanu surovinu: ");
scanf("%s", search_term);
2024-10-03 21:16:54 +00:00
2024-10-04 12:28:10 +00:00
// Prekonvertovanie hladanej suroviny do Hacker script
to_hacker_script(search_term, hacker_search);
2024-10-03 21:16:54 +00:00
2024-10-04 12:28:10 +00:00
printf("Zadaj jedalny listok:\n");
2024-10-04 12:21:36 +00:00
while (1) {
2024-10-04 12:28:10 +00:00
if (scanf("%s", dish_name) == EOF) {
break;
2024-10-03 21:16:54 +00:00
}
2024-10-04 12:28:10 +00:00
scanf("%s", dish_price);
2024-10-04 12:20:12 +00:00
2024-10-04 12:28:10 +00:00
// Vytvorenie prekonvertovanej názvu jedla
char hacker_dish_name[MAX_NAME_LENGTH];
to_hacker_script(dish_name, hacker_dish_name);
2024-10-04 12:02:06 +00:00
2024-10-04 12:28:10 +00:00
// 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);
2024-10-04 12:20:12 +00:00
count++;
2024-10-03 21:16:54 +00:00
}
}
2024-10-03 21:29:33 +00:00
printf("Nacitanych %d poloziek.\n", count);
2024-10-03 21:25:32 +00:00
return 0;
2024-10-03 21:18:50 +00:00
}