JosepRivaille

P11868: Control C402C

Apr 29th, 2015
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5.  
  6. //Pre: Llegeix un natural n>0 i n enters amb les n posicions on s'han de moure
  7. //Post: Escriu els naturals a les posicions requerides
  8. int main() {
  9.     int n;
  10.     cin >> n;
  11.     vector<int> v(2*n);
  12.     for (int i = 1; i < 2*n; i += 2) {
  13.         cin >> v[i];
  14.     }
  15.     for (int j = 0; j < 2*n - 1; j += 2) {
  16.         cin >> v[j];
  17.     }
  18.     vector<int> s(n);
  19.     int pos;
  20.     for (int k = 0; k < 2*n; ++k) {
  21.         pos = v[k];
  22.         ++k;
  23.         s[pos] = v[k];
  24.     }
  25.     bool primer = true;
  26.     for (int l = 0; l < n; ++l) {
  27.         if (not primer) cout << ' ';
  28.         cout << s[l];
  29.         primer = false;
  30.     }
  31.     cout << endl;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment