JosepRivaille

P67268: Inversió de seqüències

Apr 29th, 2015
1,720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5.  
  6. //Pre: Llegeix una seqüència
  7. //Post: Escriu la seqüència invertida
  8. int main() {
  9.     int n;
  10.     while (cin >> n) {
  11.         vector<int> v(n);
  12.         for (int i = 0; i < n; ++i) {
  13.             cin >> v[i];
  14.         }
  15.         bool primer = true;
  16.         for (int i = n-1; i >= 0; --i) {
  17.             if (not primer) cout << ' ';
  18.             else primer = false;
  19.             cout << v[i];
  20.         }
  21.         cout << endl;
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment