fork(1) download
  1. #include <algorithm>
  2. #include <forward_list>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. const forward_list<int> vec = {10, 4, 18, 7, 2, 10, 25, 30};
  9. const auto start = find_if(cbegin(vec), cend(vec), [](const auto& i){ return i == 18 || i == 25; });
  10. const auto target = find_if(start, cend(vec), [finish = *start == 18 ? 25 : 18](const auto& i){ return i == 7 || i == finish; });
  11. const auto finish = *target == 7 ? find(target, cend(vec), *start == 18 ? 25 : 18) : cend(vec);
  12.  
  13. if(start == cend(vec)) {
  14. cout << "Nether 18 nor 25 exist in vec\n";
  15. } else if(target == cend(vec) || *target == 7 && finish == cend(vec)) {
  16. cout << (*start == 18 ? "vec doesn't contain a 25 after the 18\n" : "vec doesn't contain a 18 after the 25\n");
  17. } else if(finish == cend(vec)) {
  18. cout << "vec doesn't contain a 7 between " << *start << " and " << *target << endl;
  19. } else {
  20. cout << "vec contains a 7 between " << *start << " and " << *finish << endl;
  21. }
  22. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
vec contains a 7 between 18 and 25