Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- #define MAX 100
- typedef struct
- {
- string name;
- int books[5];
- }
- lib;
- typedef struct
- {
- int id;
- int year;
- string genre;
- }
- product;
- typedef struct auth
- {
- string name;
- int books[5];
- auth()
- {
- for (int i = 0; i < 5; ++i) books[i] = 0;
- }
- }
- auth;
- void manage(string library, string book, string author){
- // TODO
- // Save info
- lib libs[MAX];
- product books[MAX];
- auth authors[MAX];
- // Read file library
- ifstream inLib(library);
- int n;
- inLib >> n;
- for (int i = 0; i < n; ++i)
- {
- inLib >> libs[i].name;
- for (int j = 0; j < 5; ++j)
- {
- inLib >> libs[i].books[j];
- }
- }
- // Read file book
- ifstream inBook(book);
- int m;
- inBook >> m;
- for (int i = 0; i < m; ++i)
- {
- inBook >> books[i].id;
- inBook >> books[i].year;
- inBook >> books[i].genre;
- }
- // Read file author
- ifstream inAuth(author);
- int p;
- inAuth >> p;
- string s;
- getline(inAuth, s);
- int id, index;
- for (int i = 0; i < p; ++i)
- {
- getline(inAuth, s);
- ofstream outTemp("temp.txt");
- outTemp << s;
- outTemp.close();
- ifstream inTemp("temp.txt");
- inTemp >> authors[i].name;
- index = 0;
- while (inTemp >> id)
- {
- authors[i].books[index] = id;
- ++index;
- }
- inTemp.close();
- }
- // Read input
- string lib_name, auth_name;
- cin >> lib_name;
- cin >> auth_name;
- int auth_index = -1;
- for (int i = 0; i < p; ++i)
- {
- if (auth_name == authors[i].name)
- {
- auth_index = i;
- break;
- }
- }
- int lib_index = -1;
- for (int i = 0; i < n; ++i)
- {
- if (lib_name == libs[i].name)
- {
- lib_index = i;
- break;
- }
- }
- if (auth_index == -1||lib_index == -1)
- {
- cout << "False";
- return;
- }
- for (int i = 0; i < 5; ++i)
- {
- id = authors[auth_index].books[i];
- if (id == 0) break;
- for (int j = 0; j < 5; ++j)
- {
- if (id == libs[lib_index].books[j])
- {
- cout << "True";
- return;
- }
- }
- }
- cout << "False";
- }
- int main()
- {
- string library = "library.txt";
- string book = "book.txt";
- string author = "author.txt";
- manage(library, book, author);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement