Aktualizovat du1/program.c
This commit is contained in:
parent
dadf03bfa6
commit
760355d358
@ -0,0 +1,71 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define MAX_LINE 256
|
||||
|
||||
char letters(char a) {
|
||||
switch (a) {
|
||||
case '0': return 'o';
|
||||
case '1': return 'i';
|
||||
case '2': return 'z';
|
||||
case '3': return 'e';
|
||||
case '4': return 'a';
|
||||
case '5': return 's';
|
||||
case '6': return 'b';
|
||||
case '7': return 't';
|
||||
case '8': return 'b';
|
||||
case '9': return 'q';
|
||||
default: return tolower(a);
|
||||
}
|
||||
}
|
||||
|
||||
void normalize(const char *input, char *output) {
|
||||
int i = 0;
|
||||
while (input[i]) {
|
||||
output[i] = letters(input[i]);
|
||||
i++;
|
||||
}
|
||||
output[i] = '\0';
|
||||
}
|
||||
|
||||
int contains_hack3r(const char *name, const char *positions) {
|
||||
char norm_name
|
||||
[MAX_LINE];
|
||||
char norm_positions[MAX_LINE];
|
||||
normalize(name, norm_name);
|
||||
normalize(positions, norm_positions);
|
||||
|
||||
return strstr(norm_name, norm_positions) != NULL;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char searched_positions[MAX_LINE];
|
||||
char dname[MAX_LINE];
|
||||
double pr;
|
||||
int a = 0;
|
||||
|
||||
printf("Zadaj hladanu surovinu:\n");
|
||||
printf("Zadaj jedalny listok:\n");
|
||||
if (!fgets(searched_positions, MAX_LINE, stdin)) {
|
||||
return 1;
|
||||
}
|
||||
searched_positions[strcspn(searched_positions, "\n")] = '\0';
|
||||
|
||||
|
||||
while (1) {
|
||||
if (!fgets(dname, MAX_LINE, stdin)) break;
|
||||
dname[strcspn(dname, "\n")] = '\0';
|
||||
if (scanf("%lf\n", &pr) != 1) {
|
||||
break;
|
||||
}
|
||||
if (contains_hack3r(dname, searched_positions)) {
|
||||
printf("%s\n%.2lf\n", dname, pr);
|
||||
}
|
||||
|
||||
a++;
|
||||
}
|
||||
|
||||
printf("\n Nacitanych %d poloziek.\n", a);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user