usaa24/cv1/program.c

79 lines
2.2 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>
#define MAX_DISHES 100
#define MAX_NAME_LEN 100
void decodovane_slovo(char *text) {
for (int i = 0; text[i]; 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;
default: text[i] = tolower(text[i]); break;
}
}
}
2024-10-01 13:36:19 +00:00
int main() {
2024-10-01 21:47:00 +00:00
char ingredient[MAX_NAME_LEN];
2024-10-01 22:29:12 +00:00
char dishes[MAX_DISHES][2][MAX_NAME_LEN];
int count = 0;
2024-10-01 21:47:00 +00:00
2024-10-01 22:29:12 +00:00
printf("Zadaj hladanu surovinu: \n");
2024-10-01 22:03:29 +00:00
if (fgets(ingredient, MAX_NAME_LEN, stdin) == NULL) {
2024-10-02 16:46:39 +00:00
return 0;
2024-10-01 22:03:29 +00:00
}
2024-10-02 16:46:39 +00:00
ingredient[strcspn(ingredient, "\n")] = '\0';
2024-10-01 21:47:00 +00:00
2024-10-01 22:29:12 +00:00
printf("Zadaj jedalny listok: \n");
2024-10-01 21:47:00 +00:00
while (1) {
char name[MAX_NAME_LEN], price[MAX_NAME_LEN];
2024-10-01 22:29:12 +00:00
2024-10-01 22:03:29 +00:00
if (fgets(name, MAX_NAME_LEN, stdin) == NULL) {
2024-10-02 16:46:39 +00:00
return 0;
2024-10-01 22:03:29 +00:00
}
2024-10-02 16:46:39 +00:00
name[strcspn(name, "\n")] = '\0';
2024-10-01 22:29:12 +00:00
2024-10-01 21:47:00 +00:00
if (strlen(name) == 0) {
break;
}
2024-10-01 22:03:29 +00:00
if (fgets(price, MAX_NAME_LEN, stdin) == NULL) {
2024-10-02 16:46:39 +00:00
return 0;
2024-10-01 22:03:29 +00:00
}
2024-10-02 16:46:39 +00:00
price[strcspn(price, "\n")] = '\0';
2024-10-01 21:47:00 +00:00
2024-10-01 22:00:31 +00:00
strncpy(dishes[count][0], name, MAX_NAME_LEN - 1);
2024-10-02 16:46:39 +00:00
dishes[count][0][MAX_NAME_LEN - 1] = '\0';
2024-10-01 22:00:31 +00:00
strncpy(dishes[count][1], price, MAX_NAME_LEN - 1);
2024-10-02 16:46:39 +00:00
dishes[count][1][MAX_NAME_LEN - 1] = '\0';
2024-10-01 22:00:31 +00:00
2024-10-01 21:47:00 +00:00
count++;
}
2024-10-02 16:46:39 +00:00
decodovane_slovo(ingredient);
2024-10-01 21:47:00 +00:00
for (int i = 0; i < count; i++) {
char decoded_name[MAX_NAME_LEN];
2024-10-01 21:57:29 +00:00
strncpy(decoded_name, dishes[i][0], MAX_NAME_LEN - 1);
2024-10-02 16:46:39 +00:00
decoded_name[MAX_NAME_LEN - 1] = '\0';
2024-10-01 21:47:00 +00:00
decodovane_slovo(decoded_name);
2024-10-02 16:46:39 +00:00
if (strstr(decoded_name, ingredient) != NULL) {
printf("%s\n%s", dishes[i][0], dishes[i][1]);
if (i < count - 1) {
printf("\n");
}
2024-10-01 21:47:00 +00:00
}
}
2024-10-02 16:46:39 +00:00
printf("Nacitanych %d poloziek.\n", count);
2024-10-01 13:36:19 +00:00
return 0;
2024-10-01 22:00:31 +00:00
}
2024-10-02 16:46:39 +00:00