#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <queue>
using namespace std;
struct Book {
string bookno;
string name;
double price;
};
int main() {
int n;
string bookno;//编号
string name; //名字
double price; //价格
Book book[100];
int k = 0;
while (cin >> bookno >> name >> price)
{
if (bookno == "0" && name == "0"&&price == 0) break;
book[k].bookno = bookno;
book[k].name = name;
book[k].price = price;
k++; //书的数量
}
//按照价格 【从大到小】排序
for (int i = 0; i < k-1; i++) { // 若以book[0]为基准
for (int j = i + 1; j < k; j++) { //依次与book[1]-book[k-1]比较
Book x = book[i];
if (book[j].price > x.price) { //交换位置
book[i] = book[j];
book[j] = x;
}
}
}
for (int i = 0; i < k; i++) { //输出
cout << book[i].bookno; printf(" ");
cout << book[i].name; printf(" ");
printf("%.2lf\n", book[i].price);
}
}
BJFU205 图书信息 按照价格【降序排列】 --->为何总是Runtime Error啊啊
于 2023-03-09 17:36:05 首次发布