Update cv1/program.c
This commit is contained in:
parent
dd530b2c7a
commit
29986823cf
@ -11,7 +11,7 @@ struct pizza {
|
||||
};
|
||||
|
||||
char hacker_script(char c) {
|
||||
if (c >= 'A' && c <= 'Z') return c + 32; // Convert uppercase to lowercase
|
||||
if (c >= 'A' && c <= 'Z') c += 32;
|
||||
switch (c) {
|
||||
case 'o': return '0';
|
||||
case 'i': return '1';
|
||||
@ -19,32 +19,32 @@ char hacker_script(char c) {
|
||||
case 'e': return '3';
|
||||
case 'a': return '4';
|
||||
case 's': return '5';
|
||||
case 'b': return '6'; // Single mapping for 'b'
|
||||
case 'b': return '6';
|
||||
case 't': return '7';
|
||||
case '8': return '8'; // Added mapping for '8'
|
||||
case '8': return '8';
|
||||
case 'q': return '9';
|
||||
default: return c; // Return unchanged for other characters
|
||||
default: return c;
|
||||
}
|
||||
}
|
||||
|
||||
void normalize_string(const char* input, char* output) {
|
||||
for (int i = 0; input[i] != '\0'; i++) {
|
||||
int i = 0;
|
||||
while (input[i] != '\0' && input[i] != '\n') {
|
||||
output[i] = hacker_script(input[i]);
|
||||
i++;
|
||||
}
|
||||
output[strlen(input)] = '\0'; // Null-terminate
|
||||
output[i] = '\0';
|
||||
}
|
||||
|
||||
int read_pizza(struct pizza* item) {
|
||||
char line[LINESIZE];
|
||||
if (fgets(line, sizeof(line), stdin) == NULL) return 0; // End of input
|
||||
if (fgets(line, sizeof(line), stdin) == NULL) return 0;
|
||||
|
||||
normalize_string(line, item->name); // Normalize the name
|
||||
normalize_string(line, item->name);
|
||||
if (fgets(line, sizeof(line), stdin) == NULL) return 0;
|
||||
item->prize = strtof(line, NULL);
|
||||
|
||||
if (fgets(line, sizeof(line), stdin) == NULL) return 0; // Read price
|
||||
item->prize = strtof(line, NULL); // Convert to float
|
||||
|
||||
return (item->prize > 0) ? 1 : 0; // Return success or failure
|
||||
}
|
||||
return (item->prize > 0) ? 1 : 0;
|
||||
|
||||
int find_string(const char* heap, const char* needle) {
|
||||
char normalized_heap[LINESIZE];
|
||||
@ -59,18 +59,21 @@ int main() {
|
||||
struct pizza menu[MENU_SIZE];
|
||||
int item_count = 0;
|
||||
|
||||
char search_term[LINESIZE]; // Renamed to avoid conflict
|
||||
char search_term[LINESIZE];
|
||||
printf("Zadaj hladanu surovinu:\n");
|
||||
fgets(search_term, sizeof(search_term), stdin);
|
||||
|
||||
|
||||
search_term[strcspn(search_term, "\n")] = '\0';
|
||||
|
||||
printf("Zadaj jedalny listok:\n");
|
||||
while (item_count < MENU_SIZE && read_pizza(&menu[item_count])) {
|
||||
item_count++;
|
||||
}
|
||||
|
||||
// Print matching items
|
||||
|
||||
for (int i = 0; i < item_count; i++) {
|
||||
if (find_string(menu[i].name, search_term)) { // Use the new function name
|
||||
if (find_string(menu[i].name, search_term)) {
|
||||
printf("%s\n%.2f\n", menu[i].name, menu[i].prize);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user