#include <iostream>
#include <string>
using namespace std;

struct Book {
    string title;
    string author;
    int price;
};

void findBooks(Book books[], int size) {
    int maxIndex = 0, minIndex = 0;

    for (int i = 1; i < size; i++) {
        if (books[i].price > books[maxIndex].price)
            maxIndex = i;
        if (books[i].price < books[minIndex].price)
            minIndex = i;
    }

    cout << "\n가장 비싼 책: " << books[maxIndex].title
         << " (" << books[maxIndex].author << "), 가격: " << books[maxIndex].price << "원" << endl;
    cout << "가장 저렴한 책: " << books[minIndex].title
         << " (" << books[minIndex].author << "), 가격: " << books[minIndex].price << "원" << endl;
}

int main() {
    Book books[3];

    for (int i = 0; i < 3; i++) {
        cin >> books[i].title >> books[i].author >> books[i].price;
    }
    findBooks(books, 3);

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: