This commit is contained in:
2024-12-05 15:46:08 +08:00
parent 08f6f4b0f4
commit 4ae4cf8554
26 changed files with 1385 additions and 1381 deletions
+50 -50
View File
@@ -1,50 +1,50 @@
#include <iomanip>
#include <iostream>
using namespace std;
typedef struct {
string id;
string name;
double price;
} book;
void swap(book &a, book &b) {
book temp = a;
a = b;
b = temp;
}
void sort(book *arr, int length) {
for (int i = 0; i < length - 1; i++) {
for (int j = 0; j < length - 1 - i; j++) {
if (arr[j].price < arr[j + 1].price) {
swap(arr[j], arr[j + 1]);
}
}
}
}
int input(book *books) {
int length = 0;
for (int length = 0; true; length++) {
cin >> books[length].id >> books[length].name >> books[length].price;
if (books[length].id == "0" && books[length].name == "0" && books[length].price == 0) {
return length;
}
}
}
void output(book *books, int length) {
for (int i = 0; i < length; i++) {
cout << books[i].id << " " << books[i].name << " " << fixed << setprecision(2) << books[i].price << endl;
}
}
int main() {
book books[100];
int length = input(books);
sort(books, length);
output(books, length);
return 0;
}
#include <iomanip>
#include <iostream>
using namespace std;
typedef struct {
string id;
string name;
double price;
} book;
void swap(book &a, book &b) {
book temp = a;
a = b;
b = temp;
}
void sort(book *arr, int length) {
for (int i = 0; i < length - 1; i++) {
for (int j = 0; j < length - 1 - i; j++) {
if (arr[j].price < arr[j + 1].price) {
swap(arr[j], arr[j + 1]);
}
}
}
}
int input(book *books) {
int length = 0;
for (int length = 0; true; length++) {
cin >> books[length].id >> books[length].name >> books[length].price;
if (books[length].id == "0" && books[length].name == "0" && books[length].price == 0) {
return length;
}
}
}
void output(book *books, int length) {
for (int i = 0; i < length; i++) {
cout << books[i].id << " " << books[i].name << " " << fixed << setprecision(2) << books[i].price << endl;
}
}
int main() {
book books[100];
int length = input(books);
sort(books, length);
output(books, length);
return 0;
}