fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. std::size_t count_123(const std::vector<int>& v)
  6. {
  7. std::size_t res = 0;
  8.  
  9. for (auto it = v.begin(); it != v.end(); )
  10. {
  11. it = std::find(it, v.end(), 1);
  12. it = std::find(it, v.end(), 2);
  13. it = std::find(it, v.end(), 3);
  14. if (it != v.end()) {
  15. ++res;
  16. }
  17. }
  18. return res;
  19. }
  20.  
  21.  
  22. int main() {
  23. std::cout << count_123({1,2,3,1,2,2,3}) << std::endl; // 2
  24. std::cout << count_123({1,2,2,2,2,2,3,1,2,3}) << std::endl; // 2
  25. std::cout << count_123({1, 3, 2, 3, 1}) << std::endl; // 1
  26. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
2
2
1