usaa24/cv1/program.c

64 lines
1.6 KiB
C

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <windows.h>
void normalize(char *str) {
for (int i = 0; str[i] != '\0'; i++) {
switch (str[i]) {
case '0': str[i] = 'o'; break;
case '1': str[i] = 'i'; break;
case '2': str[i] = 'z'; break;
case '3': str[i] = 'e'; break;
case '4': str[i] = 'a'; break;
case '5': str[i] = 's'; break;
case '6': str[i] = 'b'; break;
case '7': str[i] = 't'; break;
case '8': str[i] = 'b'; break;
case '9': str[i] = 'q'; break;
default: str[i] = tolower(str[i]); break;
}
}
}
int main() {
SetConsoleOutputCP(CP_UTF8);
char search[100];
char item_name[100];
char price[10];
int count = 0;
printf("Zadaj hladanu surovinu:");
fgets(search, sizeof(search), stdin);
search[strcspn(search, "\n")] = '\0';
normalize(search);
printf("Zadaj jedalny listok:\n");
while (1) {
fgets(item_name, sizeof(item_name), stdin);
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);
}
}
printf("Считано %d блюд.\n", count);
return 0;
}