usaa24/cv1/program.c

62 lines
1.5 KiB
C
Raw Normal View History

2024-10-01 13:36:19 +00:00
#include <stdio.h>
2024-10-01 21:47:00 +00:00
#include <string.h>
#include <ctype.h>
2024-10-03 10:42:43 +00:00
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;
2024-10-01 21:47:00 +00:00
}
}
}
2024-10-02 17:25:52 +00:00
2024-10-01 13:36:19 +00:00
int main() {
2024-10-03 10:42:43 +00:00
char search[100];
char item_name[100];
char price[10];
int count = 0;
2024-10-01 22:29:12 +00:00
2024-10-02 17:25:52 +00:00
2024-10-03 10:42:43 +00:00
printf("Zadaj hladanu surovinu:");
fgets(search, sizeof(search), stdin);
search[strcspn(search, "\n")] = '\0';
normalize(search);
2024-10-01 21:47:00 +00:00
2024-10-03 10:42:43 +00:00
printf("Zadaj jedalny listok:\n");
2024-10-01 22:00:31 +00:00
2024-10-03 10:42:43 +00:00
while (1) {
2024-10-01 22:00:31 +00:00
2024-10-03 10:42:43 +00:00
fgets(item_name, sizeof(item_name), stdin);
item_name[strcspn(item_name, "\n")] = '\0';
if (strlen(item_name) == 0) break;
2024-10-02 17:25:52 +00:00
2024-10-02 16:46:39 +00:00
2024-10-03 10:42:43 +00:00
fgets(price, sizeof(price), stdin);
price[strcspn(price, "\n")] = '\0';
count++;
2024-10-01 21:47:00 +00:00
2024-10-03 10:42:43 +00:00
char normalized_name[100];
strcpy(normalized_name, item_name);
normalize(normalized_name);
2024-10-01 21:47:00 +00:00
2024-10-03 10:42:43 +00:00
if (strstr(normalized_name, search) != NULL) {
printf("%s\n%s\n", item_name, price);
2024-10-01 21:47:00 +00:00
}
}
2024-10-02 17:25:52 +00:00
2024-10-02 18:01:23 +00:00
2024-10-03 10:42:43 +00:00
printf("Считано %d блюд.\n", count);
2024-10-01 13:36:19 +00:00
return 0;
2024-10-01 22:00:31 +00:00
}