Advertisement
GrandtherAzaMarks

LKSH 2 Task Line Of LKSH Pupils

Apr 20th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5. void Input (vector<int>& n) {for (int i = 0; i < n.size(); ++i) cin >> n[i];}
  6. void Output (vector<int> n) {for (int i = 0; i < n.size(); ++i) cout << n[i] << " ";}
  7.  
  8. int main()
  9. {
  10.     int n = 0; cin >> n;
  11.     vector<int> ingrowth(n,-1), inage(n,-1);
  12.     vector<int>::iterator it1, it2;
  13.     Input(ingrowth); Input(inage);
  14.    
  15.     vector<int> growth(0), age(0);
  16.     for (int i = 0; i < n; ++i)
  17.     {
  18.         it1 = growth.begin();
  19.         it2 = age.begin();
  20.         growth.insert(it1, ingrowth[i]);
  21.         age.insert(it2, inage[i]);
  22.         for(int i = 0;i<growth.size()-1 && growth[i]>growth[i+1] && age[i+1]-age[i] <= 5;++i)
  23.         {
  24.             swap(growth[i],growth[i+1]);
  25.             swap(age[i],age[i+1]);
  26.         }
  27.     }
  28.     Output(growth);
  29.     return 0;
  30. }
  31. /*
  32.  6
  33.  160 173 138 145 153 170
  34.  15 17 12 18 16 12
  35.  
  36. ans: 138 170 145 153 160 173
  37.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement