62 lines
1.5 KiB
C
62 lines
1.5 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
#define MAX_LENGTH 100
|
|
#define MAX_DISHES 100
|
|
|
|
char dish_name[MAX_DISHES][MAX_LENGTH];
|
|
double dish_price[MAX_DISHES];
|
|
|
|
int main() {
|
|
int count = 0;
|
|
|
|
while (count < MAX_DISHES) {
|
|
char dish[MAX_LENGTH];
|
|
char price[MAX_LENGTH];
|
|
|
|
if (fgets(dish, MAX_LENGTH, stdin) == NULL) {
|
|
break;
|
|
}
|
|
dish[strcspn(dish, "\n")] = 0;
|
|
|
|
if (strlen(dish) == 0) {
|
|
break;
|
|
}
|
|
strcpy(dish_name[count], dish);
|
|
|
|
if (fgets(price, MAX_LENGTH, stdin) == NULL) {
|
|
break;
|
|
}
|
|
price[strcspn(price, "\n")] = 0;
|
|
|
|
if (strlen(price) == 0) {
|
|
break;
|
|
}
|
|
|
|
dish_price[count] = atof(price);
|
|
count++;
|
|
}
|
|
|
|
for (int i = 0; i < count - 1; i++) {
|
|
for (int j = 0; j < count - i - 1; j++) {
|
|
if (dish_price[j] > dish_price[j + 1] ||
|
|
(dish_price[j] == dish_price[j + 1] && strcmp(dish_name[j], dish_name[j + 1]) > 0)) {
|
|
double temp_price = dish_price[j];
|
|
dish_price[j] = dish_price[j + 1];
|
|
dish_price[j + 1] = temp_price;
|
|
|
|
char temp_name[MAX_LENGTH];
|
|
strcpy(temp_name, dish_name[j]);
|
|
strcpy(dish_name[j], dish_name[j + 1]);
|
|
strcpy(dish_name[j + 1], temp_name);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
printf("%s\n%.6f\n", dish_name[i], dish_price[i]);
|
|
}
|
|
|
|
return 0;
|
|
} |