Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <vector>
- #include <algorithm>
- #include <iterator>
- using namespace std;
- const int NUMBER_NON_EXISTENT_COUNTRY = 0;
- const int DIFFERENCE = 1;
- struct Requirements {
- int income;
- int higher_education;
- int citizenship_parents;
- };
- vector<Requirements> countries;
- vector<Requirements> classmates;
- inline int findCountry(const Requirements classmate) {
- auto is_possible = [classmate](const Requirements country) {
- return classmate.higher_education >= country.higher_education && classmate.income >= country.income;
- };
- if (classmate.citizenship_parents != NUMBER_NON_EXISTENT_COUNTRY && countries[classmate.citizenship_parents - DIFFERENCE].citizenship_parents) {
- auto possible_country = countries.begin() + classmate.citizenship_parents - DIFFERENCE;
- auto another_possible_country = find_if(countries.begin(), possible_country, is_possible);
- if (another_possible_country != countries.end() && another_possible_country < possible_country)
- return distance(countries.begin(), another_possible_country) + DIFFERENCE;
- return distance(countries.begin(), possible_country) + DIFFERENCE;
- }
- auto possible_country = find_if(countries.begin(), countries.end(), is_possible);
- if (possible_country == countries.end())
- return NUMBER_NON_EXISTENT_COUNTRY;
- return distance(countries.begin(), possible_country) + DIFFERENCE;
- }
- int main() {
- ifstream fin("input.txt");
- ofstream fout("output.txt");
- int number_countries;
- int number_classmates;
- fin >> number_countries;
- countries.resize(number_countries);
- for (auto country = countries.begin(); country != countries.end(); country++) fin >> country->income;
- for (auto country = countries.begin(); country != countries.end(); country++) fin >> country->higher_education;
- for (auto country = countries.begin(); country != countries.end(); country++) fin >> country->citizenship_parents;
- fin >> number_classmates;
- classmates.resize(number_classmates);
- for (auto classmate = classmates.begin(); classmate != classmates.end(); classmate++) fin >> classmate->income;
- for (auto classmate = classmates.begin(); classmate != classmates.end(); classmate++) fin >> classmate->higher_education;
- for (auto classmate = classmates.begin(); classmate != classmates.end(); classmate++) fin >> classmate->citizenship_parents;
- for (auto classmate = classmates.begin(); classmate != classmates.end(); classmate++) fout << findCountry(*classmate) << ' ';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement