usaa24/cv1/program.c

60 lines
1.6 KiB
C
Raw Permalink 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
2024-10-03 10:59:36 +00:00
#define MAX_DISHES 100
#define MAX_LENGTH 100
void decode(char *text) {
for (int i = 0; text[i] != '\0'; 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;
2024-10-01 21:47:00 +00:00
}
2024-10-03 11:08:00 +00:00
text[i] = tolower(text[i]);
2024-10-01 21:47:00 +00:00
}
}
2024-10-01 13:36:19 +00:00
int main() {
2024-10-03 10:59:36 +00:00
char slovo[MAX_LENGTH];
char dish_name[MAX_LENGTH];
2024-10-03 11:09:07 +00:00
float price[MAX_DISHES];
2024-10-03 11:08:00 +00:00
int count = 0;
2024-10-03 10:59:36 +00:00
printf("Zadaj hladanu surovinu:\n");
fgets(slovo, MAX_LENGTH, stdin);
2024-10-03 11:08:00 +00:00
slovo[strcspn(slovo, "\n")] = 0;
decode(slovo);
2024-10-03 10:42:43 +00:00
printf("Zadaj jedalny listok:\n");
while (1) {
2024-10-03 11:09:42 +00:00
2024-10-03 10:59:36 +00:00
if (fgets(dish_name, MAX_LENGTH, stdin) == NULL || strcmp(dish_name, "\n") == 0) {
2024-10-03 11:08:00 +00:00
break;
2024-10-03 10:59:36 +00:00
}
dish_name[strcspn(dish_name, "\n")] = 0;
2024-10-03 11:09:42 +00:00
2024-10-03 11:08:00 +00:00
if (scanf("%f", &price[count]) != 1) {
break;
2024-10-03 10:59:36 +00:00
}
2024-10-03 11:09:42 +00:00
2024-10-03 11:08:00 +00:00
while (getchar() != '\n');
2024-10-03 11:09:42 +00:00
2024-10-03 10:59:36 +00:00
char normal_dish[MAX_LENGTH];
strcpy(normal_dish, dish_name);
2024-10-03 11:08:00 +00:00
decode(normal_dish);
2024-10-03 10:59:36 +00:00
if (strstr(normal_dish, slovo) != NULL) {
2024-10-03 11:08:00 +00:00
// Print the dish name and formatted price
printf("%s\n%.2f\n", dish_name, price[count]);
2024-10-01 21:47:00 +00:00
}
2024-10-03 10:59:36 +00:00
count++;
2024-10-01 21:47:00 +00:00
}
2024-10-03 10:44:04 +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
}