Advertisement
JosepRivaille

P25992: Ordenació separada

May 28th, 2015
1,086
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. const int MAX = 1000;
  7.  
  8. typedef vector<int> Row;
  9.  
  10. int main() {
  11.     Row p(MAX);
  12.     Row s(MAX);
  13.     int i = 0;
  14.     int j = 0;
  15.     int n;
  16.     while (cin >> n) {
  17.         if (n != 0) {
  18.             if (n%2 == 0) {
  19.                 p[i] = n;
  20.                 ++i;
  21.             }
  22.             else {
  23.                 s[j] = n;
  24.                 ++j;
  25.             }
  26.         }
  27.         else {
  28.             sort (p.begin(), p.begin() + i);
  29.             sort (s.begin(), s.begin() + j);
  30.             if (i > 0) cout << p[0];
  31.             for (int k = 1; k < i; ++k) cout << ' ' << p[k];
  32.             cout << endl;
  33.             if (j > 0) cout << s[j - 1];
  34.             for (int k = j - 2; k >= 0; --k) cout << ' ' << s[k];
  35.             cout << endl;
  36.             i = j = 0; 
  37.         }
  38.     }
  39. }
  40.  
  41. //JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement