初步完成第三题
This commit is contained in:
@@ -6,3 +6,4 @@ set(CMAKE_CXX_STANDARD 20)
|
|||||||
add_executable(test1
|
add_executable(test1
|
||||||
test1.cpp)
|
test1.cpp)
|
||||||
add_executable(test2 test2.cpp)
|
add_executable(test2 test2.cpp)
|
||||||
|
add_executable(test3 test3.cpp)
|
||||||
|
|||||||
+2
-2
@@ -28,7 +28,7 @@ void sort(book *arr, int size) {
|
|||||||
int main() {
|
int main() {
|
||||||
book books[100];
|
book books[100];
|
||||||
int size = 0;
|
int size = 0;
|
||||||
for (size = 0; 1; size++) {
|
for (size = 0; true; size++) {
|
||||||
cin >> books[size].id >> books[size].name >> books[size].price;
|
cin >> books[size].id >> books[size].name >> books[size].price;
|
||||||
if (books[size].id == "0" && books[size].name == "0" && books[size].price == 0) {
|
if (books[size].id == "0" && books[size].name == "0" && books[size].price == 0) {
|
||||||
break;
|
break;
|
||||||
@@ -36,7 +36,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
sort(books, size);
|
sort(books, size);
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
cout << books[i].id << " " << books[i].name << " " << fixed << setprecision(2) << books[i].price << endl;
|
cout << books[i].id << "\t" << books[i].name << "\t" << fixed << setprecision(2) << books[i].price << endl;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
string id;
|
||||||
|
string name;
|
||||||
|
double price;
|
||||||
|
} book;
|
||||||
|
|
||||||
|
void alter_to_110_percent(book *books, int length) {
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
books[i].price = books[i].price * 1.1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
book books[100];
|
||||||
|
int length = 0;
|
||||||
|
for (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) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
alter_to_110_percent(books, length);
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
cout << books[i].id << "\t" << books[i].name << "\t" << fixed << setprecision(2) << books[i].price << endl;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user