69 lines
1.4 KiB
C
69 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
|
|
#define LINE_SIZE 200
|
|
|
|
// meni cisla na znaky a aj velke na male
|
|
void normalize(char *z) {
|
|
char cis[] = "0123456789";
|
|
char pis[] = "oizeasgtbq";
|
|
|
|
for (int i = 0; z[i]; i++) {
|
|
char x = tolower((unsigned char)z[i]);
|
|
|
|
int found = 0;
|
|
for (int j = 0; j < 10; j++) {
|
|
if (x == cis[j]) {
|
|
z[i] = pis[j];
|
|
found = 1;
|
|
break;
|
|
}
|
|
}
|
|
if (!found) {
|
|
z[i] = x;
|
|
}
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
char h[LINE_SIZE];
|
|
char j[LINE_SIZE];
|
|
char price[LINE_SIZE];
|
|
int count = 0;
|
|
|
|
printf("Zadaj hladanu surovinu:\n");
|
|
if (!fgets(h, LINE_SIZE, stdin)) return 0;
|
|
h[strcspn(h, "\n")] = 0;
|
|
normalize(h);
|
|
|
|
printf("Zadaj jedalny listok:\n");
|
|
while (1) {
|
|
if (!fgets(j, LINE_SIZE, stdin)) break;
|
|
j[strcspn(j, "\n")] = 0;
|
|
if (strlen(j) == 0) break;
|
|
|
|
if (!fgets(price, LINE_SIZE, stdin)) break;
|
|
price[strcspn(price, "\n")] = 0;
|
|
|
|
count++; // počítame všetky položky
|
|
|
|
char norm_dish[LINE_SIZE];
|
|
strcpy(norm_dish, j);
|
|
normalize(norm_dish);
|
|
|
|
if (strstr(norm_dish, h) != NULL) {
|
|
printf("%s\n", j);
|
|
|
|
double con;
|
|
if(sscanf(price, "%lf", &con) == ){
|
|
printf("%.2f\n" con );
|
|
}
|
|
}
|
|
}
|
|
|
|
printf("Nacitanych %d poloziek.\n", count);
|
|
return 0;
|
|
}
|
|
|