2024-10-09 08:04:03 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char name[101];
|
|
|
|
double price;
|
|
|
|
} Pizza;
|
|
|
|
|
|
|
|
int comparePizzas(const void *a, const void *b) {
|
|
|
|
Pizza *pizzaA = (Pizza *)a;
|
|
|
|
Pizza *pizzaB = (Pizza *)b;
|
|
|
|
|
|
|
|
if (pizzaA->price < pizzaB->price) {
|
|
|
|
return -1;
|
|
|
|
} else if (pizzaA->price > pizzaB->price) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return strcmp(pizzaA->name, pizzaB->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2024-10-09 08:08:03 +00:00
|
|
|
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;
|
|
|
|
}
|
2024-10-09 08:04:03 +00:00
|
|
|
|
|
|
|
qsort(menu, menuSize, sizeof(Pizza), comparePizzas);
|
|
|
|
|
|
|
|
for (int i = 0; i < menuSize; i++) {
|
|
|
|
printf("%s\n%.6f\n", menu[i].name, menu[i].price);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|