Initializacia
This commit is contained in:
parent
839307eea0
commit
df6e7666dc
124
cv1/program.c
124
cv1/program.c
@ -1,89 +1,69 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define LINESIZE 100
|
||||
#define MENU_SIZE 100
|
||||
#define MAX_INPUT_LENGTH 100
|
||||
|
||||
struct pizza {
|
||||
char name[LINESIZE];
|
||||
float price;
|
||||
// Define the "Hack3r scr1pt" mapping
|
||||
char hack3r_script_mapping[][2] = {
|
||||
{'0', 'o'},
|
||||
{'1', 'i'},
|
||||
{'2', 'z'},
|
||||
{'3', 'e'},
|
||||
{'4', 'a'},
|
||||
{'5', 's'},
|
||||
{'6', 'b'},
|
||||
{'7', 't'},
|
||||
{'8', 'b'},
|
||||
{'9', 'q'}
|
||||
};
|
||||
|
||||
char hacker_script(char l) {
|
||||
switch (tolower(l)) {
|
||||
case 'o': return '0';
|
||||
case 'i': return '1';
|
||||
case 'z': return '2';
|
||||
case 'e': return '3';
|
||||
case 'a': return '4';
|
||||
case 's': return '5';
|
||||
case 'b': return '6';
|
||||
case 't': return '7';
|
||||
case 'q': return '9';
|
||||
default: return tolower(l);
|
||||
}
|
||||
}
|
||||
|
||||
void transform_to_hacker_script(const char *src, char *dest) {
|
||||
while (*src) {
|
||||
*dest++ = hacker_script(*src++);
|
||||
}
|
||||
*dest = '\0';
|
||||
}
|
||||
|
||||
int contains_normalized(const char *name, const char *search) {
|
||||
char transformed_name[LINESIZE], transformed_search[LINESIZE];
|
||||
|
||||
transform_to_hacker_script(name, transformed_name);
|
||||
transform_to_hacker_script(search, transformed_search);
|
||||
|
||||
return strstr(transformed_name, transformed_search) != NULL;
|
||||
}
|
||||
|
||||
int read_pizza(struct pizza *item) {
|
||||
char line[LINESIZE];
|
||||
|
||||
if (!fgets(item->name, LINESIZE, stdin)) {
|
||||
return 0;
|
||||
}
|
||||
item->name[strcspn(item->name, "\n")] = '\0';
|
||||
|
||||
if (!fgets(line, LINESIZE, stdin)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
item->price = strtof(line, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
struct pizza menu[MENU_SIZE];
|
||||
char search[LINESIZE];
|
||||
char ingredient[MAX_INPUT_LENGTH];
|
||||
char menu_item[MAX_INPUT_LENGTH];
|
||||
int count = 0;
|
||||
|
||||
printf("Zadaj hladanu surovinu:\n");
|
||||
if (!fgets(search, LINESIZE, stdin)) {
|
||||
printf("Error reading input.\n");
|
||||
return 1;
|
||||
}
|
||||
search[strcspn(search, "\n")] = '\0';
|
||||
// Read the ingredient to be searched
|
||||
printf("Zadaj hladanu surovinu: ");
|
||||
fgets(ingredient, MAX_INPUT_LENGTH, stdin);
|
||||
ingredient[strcspn(ingredient, "\n")] = 0; // Remove newline character
|
||||
|
||||
printf("Zadaj jedalny listok:\n");
|
||||
while (count < MENU_SIZE && read_pizza(&menu[count])) {
|
||||
count++;
|
||||
}
|
||||
// Read the menu items
|
||||
while (1) {
|
||||
printf("Zadaj jedalny listok: ");
|
||||
fgets(menu_item, MAX_INPUT_LENGTH, stdin);
|
||||
if (feof(stdin) || strlen(menu_item) == 1) {
|
||||
break;
|
||||
}
|
||||
menu_item[strcspn(menu_item, "\n")] = 0; // Remove newline character
|
||||
|
||||
int found_count = 0;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (contains_normalized(menu[i].name, search)) {
|
||||
printf("%s\n%.2f\n", menu[i].name, menu[i].price);
|
||||
found_count++;
|
||||
// Apply the "Hack3r scr1pt" mapping to the name
|
||||
char name_hack3r[MAX_INPUT_LENGTH];
|
||||
int j = 0;
|
||||
for (int i = 0; menu_item[i]; i++) {
|
||||
int found = 0;
|
||||
for (int k = 0; k < 10; k++) {
|
||||
if (menu_item[i] == hack3r_script_mapping[k][0]) {
|
||||
name_hack3r[j++] = hack3r_script_mapping[k][1];
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
name_hack3r[j++] = tolower(menu_item[i]);
|
||||
}
|
||||
}
|
||||
name_hack3r[j] = 0;
|
||||
|
||||
// Search for the ingredient in the name
|
||||
if (strstr(name_hack3r, ingredient) != NULL) {
|
||||
printf("%s\n", menu_item);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
// Display the count of successful searches
|
||||
printf("Nacitanych %d poloziek.\n", count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user