trydu
This commit is contained in:
parent
2c373e350e
commit
a593dc689b
BIN
du1/program
Executable file
BIN
du1/program
Executable file
Binary file not shown.
94
du1/program.c
Normal file
94
du1/program.c
Normal file
@ -0,0 +1,94 @@
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define LINE_SIZE 100
|
||||
#define MAXIT 100
|
||||
|
||||
struct pizza{
|
||||
float prize;
|
||||
char name[LINE_SIZE];
|
||||
};
|
||||
|
||||
char hacker_script(char c){
|
||||
c = tolower((unsigned char)c);
|
||||
switch(c){
|
||||
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 c;}
|
||||
}
|
||||
|
||||
|
||||
void normalize(const char *source, char *dest){
|
||||
int i =0;
|
||||
while(source[i]!='\0'){
|
||||
dest[i]= hacker_script(source[i]);
|
||||
i++;
|
||||
}
|
||||
dest[i]='\0';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int read_pizza(struct pizza *item){
|
||||
char line_1[LINE_SIZE];
|
||||
char line_2[LINE_SIZE];
|
||||
|
||||
if (fgets(line_1,LINE_SIZE,stdin)==NULL) return 0;
|
||||
if (fgets(line_2,LINE_SIZE,stdin)==NULL) return 0;
|
||||
|
||||
line_1[strcspn(line_1,"\n")] = '\0';
|
||||
line_2[strcspn(line_2,"\n")] = '\0';
|
||||
|
||||
float price = 0.0;
|
||||
if (sscanf(line_2, "%f", &price)!=1) return 0;
|
||||
|
||||
strcpy(item->name, line_1);
|
||||
item->prize = price;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
char search[LINE_SIZE];
|
||||
char normal_search[LINE_SIZE];
|
||||
|
||||
struct pizza list[MAXIT];
|
||||
int cnt = 0;
|
||||
|
||||
printf("Zadaj hladanu surovinu:\n");
|
||||
if (fgets(search, LINE_SIZE, stdin)==NULL) return 0;
|
||||
search[strcspn(search,"\n")] = '\0';
|
||||
|
||||
normalize(search, normal_search);
|
||||
|
||||
printf("Zadaj jedalny listok:\n");
|
||||
|
||||
|
||||
while(cnt<MAXIT&&read_pizza(&list[cnt])){ cnt++;}
|
||||
for (int i =0;i<cnt; i++){
|
||||
char normal_name[LINE_SIZE];
|
||||
normalize(list[i].name, normal_name);
|
||||
|
||||
if (strstr(normal_name, normal_search) != NULL) {
|
||||
printf("%s\n", list[i].name);
|
||||
printf("%.2f\n", list[i].prize);
|
||||
}
|
||||
|
||||
}
|
||||
printf("Nacitanych %d poloziek.\n", cnt);
|
||||
return 0;
|
||||
}
|
7
du1/vstup.txt
Normal file
7
du1/vstup.txt
Normal file
@ -0,0 +1,7 @@
|
||||
bryndz
|
||||
8rynd20va P1zza
|
||||
7.50
|
||||
Ja8lkov4 Pizza
|
||||
6.50
|
||||
5penatov3 kal2on3
|
||||
8.20
|
Loading…
Reference in New Issue
Block a user