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
+10 -10
View File
@@ -1,10 +1,10 @@
cmake_minimum_required(VERSION 3.29)
project(homework1)
set(CMAKE_CXX_STANDARD 20)
add_executable(test1
test1.cpp)
add_executable(test2 test2.cpp)
add_executable(test3 test3.cpp)
add_executable(test4 test4.cpp)
cmake_minimum_required(VERSION 3.29)
project(homework1)
set(CMAKE_CXX_STANDARD 20)
add_executable(test1
test1.cpp)
add_executable(test2 test2.cpp)
add_executable(test3 test3.cpp)
add_executable(test4 test4.cpp)
+34 -34
View File
@@ -1,34 +1,34 @@
#include <iostream>
#include <iomanip>
using namespace std;
typedef struct book {
string id;
string name;
double price;
} book;
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);
cout << length << endl;
output(books, length);
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
typedef struct book {
string id;
string name;
double price;
} book;
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);
cout << length << endl;
output(books, length);
return 0;
}
+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;
}
+40 -40
View File
@@ -1,40 +1,40 @@
#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 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);
alter_to_110_percent(books, length);
output(books, length);
return 0;
}
#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 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);
alter_to_110_percent(books, length);
output(books, length);
return 0;
}
+72 -72
View File
@@ -1,72 +1,72 @@
#include <iostream>
#include <iomanip>
using namespace std;
typedef struct {
string id;
string name;
double price;
} book;
typedef struct {
book *books;
int number_of_books;
} book_and_number;
double find_max_price(book *books, int n) {
double max_price = 0;
for (int i = 0; i < n; i++) {
if (books[i].price > max_price) {
max_price = books[i].price;
}
}
return max_price;
}
book_and_number max_price_books(book *books, int n) {
double max_price = find_max_price(books, n);
book_and_number books_and_number;
books_and_number.books = new book[100];
books_and_number.number_of_books = 0;
for (int i = 0; i < n; i++) {
if (books[i].price == max_price) {
books_and_number.books[i].id = books[i].id;
books_and_number.books[i].name = books[i].name;
books_and_number.books[i].price = books[i].price;
books_and_number.number_of_books++;
}
}
return books_and_number;
}
void input(book *books, int n) {
for (int i = 0; i < n; i++) {
cin >> books[i].id >> books[i].name >> books[i].price;
}
}
void output(book_and_number *books_and_number) {
cout << books_and_number->number_of_books << endl;
for (int i = 0; true; i++) {
if (books_and_number->books[i].price != 0) {
for (int j = 1; j < i + books_and_number->number_of_books; j++) {
cout << books_and_number->books[i].id << " " << books_and_number->books[i].name << " " << fixed <<
setprecision(2) << books_and_number->books[i].price << endl;
}
break;
}
}
}
int main() {
book books[100];
int n;
cin >> n;
input(books, n);
find_max_price(books, n);
book_and_number books_and_number = max_price_books(books, n);
output(&books_and_number);
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
typedef struct {
string id;
string name;
double price;
} book;
typedef struct {
book *books;
int number_of_books;
} book_and_number;
double find_max_price(book *books, int n) {
double max_price = 0;
for (int i = 0; i < n; i++) {
if (books[i].price > max_price) {
max_price = books[i].price;
}
}
return max_price;
}
book_and_number max_price_books(book *books, int n) {
double max_price = find_max_price(books, n);
book_and_number books_and_number;
books_and_number.books = new book[100];
books_and_number.number_of_books = 0;
for (int i = 0; i < n; i++) {
if (books[i].price == max_price) {
books_and_number.books[i].id = books[i].id;
books_and_number.books[i].name = books[i].name;
books_and_number.books[i].price = books[i].price;
books_and_number.number_of_books++;
}
}
return books_and_number;
}
void input(book *books, int n) {
for (int i = 0; i < n; i++) {
cin >> books[i].id >> books[i].name >> books[i].price;
}
}
void output(book_and_number *books_and_number) {
cout << books_and_number->number_of_books << endl;
for (int i = 0; true; i++) {
if (books_and_number->books[i].price != 0) {
for (int j = 1; j < i + books_and_number->number_of_books; j++) {
cout << books_and_number->books[i].id << " " << books_and_number->books[i].name << " " << fixed <<
setprecision(2) << books_and_number->books[i].price << endl;
}
break;
}
}
}
int main() {
book books[100];
int n;
cin >> n;
input(books, n);
find_max_price(books, n);
book_and_number books_and_number = max_price_books(books, n);
output(&books_and_number);
return 0;
}