This commit is contained in:
Deinerovych 2024-10-09 10:08:03 +02:00
parent d4adaf65b0
commit 21af9602eb

View File

@ -21,15 +21,23 @@ int comparePizzas(const void *a, const void *b) {
}
int main() {
Pizza menu[] = {
{"Salamovo Fazulova pizza", 7.96},
{"Sunkova pizza", 5.77},
{"Bryndzova pizza", 8.67},
{"Zelerova pizza", 8.86},
{"Slaninovo Sunkova pizza", 7.55},
{"Slaninova pizza", 5.16}
};
int menuSize = sizeof(menu) / sizeof(menu[0]);
Pizza menu[100]; // Максимум 100 пицц
int menuSize = 0;
while (1) {
Pizza pizza;
if (fgets(pizza.name, sizeof(pizza.name), stdin) == NULL) {
break;
}
// Удаляем символ новой строки, если он есть
pizza.name[strcspn(pizza.name, "\n")] = 0;
if (scanf("%lf%*c", &pizza.price) != 1) {
break;
}
menu[menuSize++] = pizza;
}
qsort(menu, menuSize, sizeof(Pizza), comparePizzas);