Initializacia#
This commit is contained in:
		
						commit
						a1242f315f
					
				@ -1,7 +1,99 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
<<<<<<< HEAD
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    	
 | 
			
		||||
    return 0;
 | 
			
		||||
=======
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <ctype.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#define LINESIZE 100
 | 
			
		||||
#define MENU_SIZE 100
 | 
			
		||||
 | 
			
		||||
struct pizza {
 | 
			
		||||
    char name[LINESIZE];
 | 
			
		||||
    float price;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
char hacker_script(char l) {
 | 
			
		||||
    switch (l) {
 | 
			
		||||
        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 l;
 | 
			
		||||
    }
 | 
			
		||||
>>>>>>> e09f5c99e3015efbf8fe09d6ee464b03f7640013
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
 | 
			
		||||
    for (int i = 0; transformed_name[i]; i++) {
 | 
			
		||||
        transformed_name[i] = tolower(transformed_name[i]);
 | 
			
		||||
    }
 | 
			
		||||
    for (int i = 0; transformed_search[i]; i++) {
 | 
			
		||||
        transformed_search[i] = tolower(transformed_search[i]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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];
 | 
			
		||||
    int count = 0;
 | 
			
		||||
 | 
			
		||||
    printf("Zadaj hladanu surovinu:\n");
 | 
			
		||||
    if (!fgets(search, LINESIZE, stdin)) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    search[strcspn(search, "\n")] = '\0';
 | 
			
		||||
 | 
			
		||||
    printf("Zadaj jedalny listok:\n");
 | 
			
		||||
    while (count < MENU_SIZE && read_pizza(&menu[count])) {
 | 
			
		||||
        count++;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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++;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    printf("Nacitanych %d poloziek.\n", count);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,55 +1,61 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <ctype.h>
 | 
			
		||||
 | 
			
		||||
#define LINE_SIZE 100
 | 
			
		||||
#define LIST_SIZE 100
 | 
			
		||||
#define MAX_NAME_LENGTH 100
 | 
			
		||||
#define MAX_ITEMS 100
 | 
			
		||||
 | 
			
		||||
struct pizza{
 | 
			
		||||
    char name[LINE_SIZE];
 | 
			
		||||
typedef struct {
 | 
			
		||||
    char name[MAX_NAME_LENGTH];
 | 
			
		||||
    float price;
 | 
			
		||||
}
 | 
			
		||||
} Pizza;
 | 
			
		||||
 | 
			
		||||
int read_pizza_list(struct pizza* list){
 | 
			
		||||
    char buffer[LINE_SIZE]
 | 
			
		||||
    while(fgets(buffer, LINE_SIZT, stdin) == 0){
 | 
			
		||||
        
 | 
			
		||||
int compare(const void *a, const void *b) {
 | 
			
		||||
    Pizza *pizzaA = (Pizza *)a;
 | 
			
		||||
    Pizza *pizzaB = (Pizza *)b;
 | 
			
		||||
 | 
			
		||||
    if (pizzaA->price != pizzaB->price) {
 | 
			
		||||
        return (pizzaA->price > pizzaB->price) - (pizzaA->price < pizzaB->price);
 | 
			
		||||
    }
 | 
			
		||||
    return strcasecmp(pizzaA->name, pizzaB->name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int read_item(struct pizza* list) {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int main(){
 | 
			
		||||
    struct pizza vacerajsia = {.name = "Vajcova pizza", .price = 0.2};
 | 
			
		||||
    printf("Pizza: %s, cena: %f/n", vacerajsia.name, vacerajsia.price -0.1);
 | 
			
		||||
int read_pizza_list(Pizza *menu) {
 | 
			
		||||
    int count = 0;
 | 
			
		||||
    char input[MAX_NAME_LENGTH];
 | 
			
		||||
    
 | 
			
		||||
    // Prechadzajte vsetky miesta jedalneho listka
 | 
			
		||||
    int counter = 0;
 | 
			
		||||
    for (int i=0; i< LIST_SIZE; i++){
 | 
			
		||||
        struct pizza item;
 | 
			
		||||
        memset(&item,0,sizeof(struct pizza));
 | 
			
		||||
        // Nacitajte polozku do pomocnej premennej
 | 
			
		||||
        // Na nacitanie pouzite vlastny kod
 | 
			
		||||
        int r = read_item(&item);
 | 
			
		||||
        if (r){
 | 
			
		||||
            // Ak sa nacitanie podarilo, skopirujte polozku do pola
 | 
			
		||||
            memcpy(&listok[i],&item,sizeof(struct pizza));
 | 
			
		||||
            // Spocitame uspesne nacitane polozky
 | 
			
		||||
            counter += 1;
 | 
			
		||||
        }
 | 
			
		||||
        else{
 | 
			
		||||
            // Ak sa nacitanie nepodarilo, nasli sme poslednu polozku
 | 
			
		||||
            // Prerusim nacitanie
 | 
			
		||||
    // Nacitame pizza
 | 
			
		||||
    while (count < MAX_ITEMS && fgets(input, sizeof(input), stdin)) {
 | 
			
		||||
        input[strcspn(input, "\n")] = 0; // Odstran znak noveho riadku
 | 
			
		||||
        
 | 
			
		||||
        // Nacitame cenu pizze
 | 
			
		||||
        char price_str[10];
 | 
			
		||||
        if (fgets(price_str, sizeof(price_str), stdin) == NULL) {
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        float price = atof(price_str);
 | 
			
		||||
        if (price <= 0) {
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        strncpy(menu[count].name, input, MAX_NAME_LENGTH - 1);
 | 
			
		||||
        menu[count].price = price;
 | 
			
		||||
        count++;
 | 
			
		||||
    }
 | 
			
		||||
    // Na konci budemem mat nacitany jedalny listok
 | 
			
		||||
    // V premennej counter je pocet uspesne nacitanych poloziek
 | 
			
		||||
    return 0;
 | 
			
		||||
    return count;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    Pizza menu[MAX_ITEMS];
 | 
			
		||||
    
 | 
			
		||||
    int item_count = read_pizza_list(menu);
 | 
			
		||||
    
 | 
			
		||||
    qsort(menu, item_count, sizeof(Pizza), compare);
 | 
			
		||||
    
 | 
			
		||||
    for (int i = 0; i < item_count; i++) {
 | 
			
		||||
        printf("%s\n%.6f\n", menu[i].name, menu[i].price);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user