fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main() {
  7. vector<int> array;
  8. while(true){
  9. int x; cin >> x;
  10. if(!cin)
  11. break;
  12. array.push_back(x);
  13. }
  14.  
  15. auto first = find_if(array.begin(), array.end(), [] (int x) { return x&1; });
  16. cout << *max_element(first, array.end(), [] (int largest, int x) {
  17. if(x & 1)
  18. return largest < x;
  19. else
  20. return false;
  21. });
  22. return 0;
  23. }
Success #stdin #stdout 0s 16056KB
stdin
12 9 8 7 11 6 5  4 3 2 1
stdout
11