LegendDario

Olimpiadi Liste

Mar 21st, 2018
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <list>
  4. #include <algorithm>
  5. #include <iterator>
  6.  
  7. using namespace std;
  8.  
  9. int rec(list<int> A, int N) {
  10.     for(list<int>::iterator r = A.begin(); r != A.end(); ++r)
  11.         cout << *r <<" ";
  12.    
  13.     cout <<"\n";
  14.    
  15.     if (N > 1) {
  16.         list <int>::iterator i2 = A.begin();
  17.         for (list <int>::iterator i = A.begin(); i != A.end();i++) {
  18.            
  19.             i2++;
  20.             int sum = *i + *(i2);
  21.            
  22.             //cout <<"    " << sum << "\n";
  23.             if (sum % 2 != 0)
  24.             {
  25.  
  26.                 list <int> b;
  27.                 for(list <int>::iterator k = A.begin();k!=i;k++)
  28.                     b.push_back(*k);
  29.                
  30.                
  31.                 for(list <int>::iterator k = ++i2;k!=A.end();k++)
  32.                     b.push_back(*k);
  33.                
  34.                 i2--;
  35.                 return rec(b, N - 2);
  36.             }
  37.            
  38.         }
  39.        
  40.     }
  41.     return *A.begin();
  42. }
  43.  
  44.  
  45.  
  46. int main(int argc, char** argv) {
  47.     ifstream in("input.txt");
  48.     ofstream out("output.txt");
  49.     int n;
  50.     in >> n;
  51.     int d;
  52.     list<int> a;
  53.     for (int i = 0; i < n; i++) {
  54.         in >> d;
  55.         a.push_back(d);
  56.     }
  57.    
  58.    
  59.     out << rec(a, n);
  60.  
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment