Initializacia

This commit is contained in:
Kozar 2024-10-02 12:27:38 +00:00
parent 3cbf4047a2
commit c2c30fbd59

View File

@ -1,5 +1,105 @@
#include <stdio.h>
int main() {
return 0;
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#define LINESIZE 100
#define MENU_SiZE 100
// Štruktúra pre položku jedálneho lístka
struct pizza{
char name[LINESIZE];
float price;
}
// Prepisovací algoritmus pre "Hack3r scr1pt"
char hacker_script(char l){
switch(tolower(char 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(c);
}
}
// Function to transform a string into "Hack3r scr1pt"
void transform_to_hacker_script(const char *src, char *dest) {
while (*src) {
*dest++ = hacker_script(*src++);
}
*dest = '\0';
}
// Function to search for a normalized string in the name
int contains_normalized(const char *name, const char *search) {
char transformed_name[LINESIZE], transformed_search[LINESIZE];
// Transform both strings
transform_to_hacker_script(name, transformed_name);
transform_to_hacker_script(search, transformed_search);
// Search for the string in the name
return strstr(transformed_name, transformed_search) != NULL;
}
// Function to read a single menu item
int read_pizza(struct pizza *item) {
char line[LINESIZE];
// Read the name
if (!fgets(item->name, LINESIZE, stdin)) {
return 0; // End of input
}
// Remove newline character
item->name[strcspn(item->name, "\n")] = '\0';
// Read the price
if (!fgets(line, LINESIZE, stdin)) {
return 0; // Failed to read price
}
// Convert string to float
item->price = strtof(line, NULL);
return 1; // Successfully read
}
int main() {
struct pizza menu[MENU_SIZE];
char search[LINESIZE];
int count = 0;
// Read the search string
printf("Zadaj hladanu surovinu:\n");
fgets(search, LINESIZE, stdin);
search[strcspn(search, "\n")] = '\0'; // Remove newline
printf("Zadaj jedalny listok:\n");
// Read the menu items
while (read_pizza(&menu[count])) {
count++;
}
printf("\nVysledky vyhladavania:\n");
// Search and print items that match the search string
int found_count = 0;
for (int i = 0; i < count; i++) {
if (contains_normalized(menu[i].name, search)) {
printf("%s\n%.2f\n", menu[i].name, menu[i].price);
found_count++;
}
}
// Print the total number of loaded items
printf("Nacitanych %d poloziek.\n", count);s
return 0;
}