106 lines
2.2 KiB
C
106 lines
2.2 KiB
C
#define LINE_SIZE 100
|
|
#define POCET_JEDAL 100000 //macros pre velky vstupy a vystupy
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
struct pizza ///materialy z cvicenia
|
|
{ float prize;
|
|
char name[LINE_SIZE];
|
|
};
|
|
struct pizza jedalny_listok[POCET_JEDAL];
|
|
struct pizza *prva = jedalny_listok;
|
|
struct pizza *druha = jedalny_listok + 1;
|
|
struct pizza *tretia = &jedalny_listok[2];
|
|
|
|
|
|
|
|
|
|
char hacker_script(char c) {
|
|
|
|
|
|
if (isupper(c)) {
|
|
return tolower(c);
|
|
}
|
|
|
|
|
|
const char numbers[] = "0123456789";
|
|
const char letters[] = "oizeasbtbq";
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
if (c == numbers[i]) {
|
|
return letters[i];
|
|
}
|
|
}
|
|
|
|
return c;
|
|
}
|
|
int read_pizza(struct pizza *item) {
|
|
char line[LINE_SIZE];
|
|
char line2[LINE_SIZE];
|
|
|
|
|
|
char *endptr;
|
|
float value = strtof(line2, &endptr);
|
|
|
|
if (value == 0.0F)
|
|
return 0;
|
|
|
|
strcpy(item->name, line);
|
|
item->prize = value;
|
|
|
|
return 1;
|
|
}
|
|
|
|
|
|
int search_string(const char* heap, const char* needle) {
|
|
|
|
int heap_len = strlen(heap);
|
|
int needle_len = strlen(needle);
|
|
|
|
for (int i = 0; i <= heap_len - needle_len; i++) {
|
|
int j;
|
|
for (j = 0; j < needle_len; j++) {
|
|
char perm_n = hacker_script(needle[j]);
|
|
char perm_h = hacker_script(heap[i + j]);
|
|
|
|
|
|
if ((perm_n == '6' && perm_h == '8') || (perm_n == '8' && perm_h == '6')) {
|
|
continue;
|
|
}
|
|
|
|
if (perm_n != perm_h) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (j == needle_len) {
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
int main() {
|
|
printf("Zadaj hladanu surovinu:\n");
|
|
char search[LINE_SIZE];
|
|
if (!fgets(search, sizeof(search), stdin)) {
|
|
return 1;}
|
|
search[strcspn(search, "\n")] = '\0';
|
|
printf("Zadaj jedalny listok:\n");
|
|
|
|
int loaded = 0;
|
|
while (loaded < POCET_JEDAL && read_pizza(&jedalny_listok[loaded])) {
|
|
loaded++;
|
|
}
|
|
|
|
for(int i = 0; i<loaded; i++){
|
|
if(search_string(jedalny_listok[i].name , search) != -1){
|
|
printf("%s%.2f\n", jedalny_listok[i].name, jedalny_listok[i].prize);
|
|
}
|
|
}
|
|
printf("Nacitanych %d poloziek.\n", loaded);
|
|
return 0;
|
|
}
|