fork 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 int a[] = { 18, 25 };
  10. const auto start = find_first_of(cbegin(vec), cend(vec), cbegin(a), cend(a));
  11. const int b[] = { *start == *cbegin(a) ? *crbegin(a) : *cbegin(a), 7 };
  12. const auto target = find_first_of(start, cend(vec), cbegin(b), cend(b));
  13. const auto finish = *target == *crbegin(b) ? find(target, cend(vec), *cbegin(b)) : cend(vec);
  14.  
  15. if(start == cend(vec)) {
  16. cout << "Nether " << *cbegin(a) << " nor " << *crbegin(a) << " exist in vec\n";
  17. } else if(target == cend(vec) || *target == *crbegin(b) && finish == cend(vec)) {
  18. cout << "vec doesn't contain a " << *cbegin(b) << " after the " << *start << endl;
  19. } else if(finish == cend(vec)) {
  20. cout << "vec doesn't contain a 7 between " << *start << " and " << *target << endl;
  21. } else {
  22. cout << "vec contains a 7 between " << *start << " and " << *finish << endl;
  23. }
  24. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
vec contains a 7 between 18 and 25