commit f73bcfb4ddf30a2a77b3f466eabc8172a679c153 Author: Denis Landa Date: Wed Oct 8 09:38:46 2025 +0200 2 diff --git a/du2/program.c b/du2/program.c new file mode 100644 index 0000000..834d81a --- /dev/null +++ b/du2/program.c @@ -0,0 +1,52 @@ +#include +#include +#include + +#define MAX 1000 +#define SIZE 101 + +struct pizza { + char name[SIZE]; + float price; +}; + +int main() { + struct pizza list[MAX]; + int count = 0; + + char name[SIZE]; + char price_str[SIZE]; + float price; + + while (1) { + if (fgets(name, SIZE, stdin) == NULL) break; + name[strcspn(name, "\n")] = 0; + if (strlen(name) == 0) break; + if (fgets(price_str, SIZE, stdin) == NULL) break; + price_str[strcspn(price_str, "\n")] = 0; + if (sscanf(price_str, "%f", &price) != 1) break; + if (price <= 0) break; + + strcpy(list[count].name, name); + list[count].price = price; + count++; + if (count >= MAX) break; + } + + for (int i = 0; i < count - 1; i++) { + for (int j = 0; j < count - i - 1; j++) { + if (list[j].price > list[j + 1].price || + (list[j].price == list[j + 1].price && strcmp(list[j].name, list[j + 1].name) > 0)) { + struct pizza temp = list[j]; + list[j] = list[j + 1]; + list[j + 1] = temp; + } + } + } + for (int i = 0; i < count; i++) { + printf("%s\n%.6f\n", list[i].name, list[i].price); + } + + return 0; +} +