Advertisement
soulseb

Untitled

Mar 29th, 2023
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. #include <fstream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <iterator>
  5.  
  6. using namespace std;
  7.  
  8. const int NUMBER_NON_EXISTENT_COUNTRY = 0;
  9. const int DIFFERENCE = 1;
  10.  
  11. struct Requirements {
  12.  
  13. int income;
  14. int higher_education;
  15. int citizenship_parents;
  16. };
  17.  
  18. vector<Requirements> countries;
  19.  
  20. vector<Requirements> classmates;
  21.  
  22. inline int findCountry(const Requirements classmate) {
  23.  
  24. auto is_possible = [classmate](const Requirements country) {
  25. return classmate.higher_education >= country.higher_education && classmate.income >= country.income;
  26. };
  27.  
  28. if (classmate.citizenship_parents != NUMBER_NON_EXISTENT_COUNTRY && countries[classmate.citizenship_parents - DIFFERENCE].citizenship_parents) {
  29.  
  30. auto possible_country = countries.begin() + classmate.citizenship_parents - DIFFERENCE;
  31. auto another_possible_country = find_if(countries.begin(), possible_country, is_possible);
  32.  
  33. if (another_possible_country != countries.end() && another_possible_country < possible_country)
  34. return distance(countries.begin(), another_possible_country) + DIFFERENCE;
  35.  
  36. return distance(countries.begin(), possible_country) + DIFFERENCE;
  37. }
  38.  
  39. auto possible_country = find_if(countries.begin(), countries.end(), is_possible);
  40.  
  41. if (possible_country == countries.end())
  42. return NUMBER_NON_EXISTENT_COUNTRY;
  43.  
  44. return distance(countries.begin(), possible_country) + DIFFERENCE;
  45. }
  46.  
  47. int main() {
  48.  
  49. ifstream fin("input.txt");
  50.  
  51. ofstream fout("output.txt");
  52.  
  53. int number_countries;
  54. int number_classmates;
  55.  
  56. fin >> number_countries;
  57.  
  58. countries.resize(number_countries);
  59.  
  60. for (auto country = countries.begin(); country != countries.end(); country++) fin >> country->income;
  61.  
  62. for (auto country = countries.begin(); country != countries.end(); country++) fin >> country->higher_education;
  63.  
  64. for (auto country = countries.begin(); country != countries.end(); country++) fin >> country->citizenship_parents;
  65.  
  66. fin >> number_classmates;
  67.  
  68. classmates.resize(number_classmates);
  69.  
  70. for (auto classmate = classmates.begin(); classmate != classmates.end(); classmate++) fin >> classmate->income;
  71.  
  72. for (auto classmate = classmates.begin(); classmate != classmates.end(); classmate++) fin >> classmate->higher_education;
  73.  
  74. for (auto classmate = classmates.begin(); classmate != classmates.end(); classmate++) fin >> classmate->citizenship_parents;
  75.  
  76. for (auto classmate = classmates.begin(); classmate != classmates.end(); classmate++) fout << findCountry(*classmate) << ' ';
  77.  
  78. return 0;
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement