fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5.  
  6.  
  7. void foo(std::vector<int> v, int n)
  8. {
  9. #if 1
  10. std::sort(v.begin(), v.end());
  11. v.erase(std::unique(v.begin(), v.end()), v.end());
  12. #endif
  13.  
  14. for (const auto& e1 : v)
  15. {
  16. for (const auto& e2 : v)
  17. {
  18. if (e2 == e1) {
  19. continue;
  20. }
  21. for (const auto& e3 : v)
  22. {
  23. if (e3 == e1 || e3 == e2) {
  24. continue;
  25. }
  26. if (e1 >= e2 + e3 || e2 >= e1 + e3 || e3 >= e1 + e2) {
  27. continue;
  28. }
  29. const auto total = e1 + e2 + e3;
  30. std::cout << e1 << "+" << e2 << "+" << e3 << "=" << total;
  31. if (total < n) {
  32. std::cout << " is less than " << n << std::endl;
  33. } else if (total == n) {
  34. std::cout << " is equal to " << n << std::endl;
  35. } else {
  36. std::cout << " is more than " << n << std::endl;
  37. }
  38. }
  39. }
  40. }
  41. }
  42.  
  43.  
  44.  
  45.  
  46. int main() {
  47. foo({1, 2, 3, 3, 4, 5}, 11);
  48. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
2+3+4=9 is less than 11
2+4+3=9 is less than 11
2+4+5=11 is equal to 11
2+5+4=11 is equal to 11
3+2+4=9 is less than 11
3+4+2=9 is less than 11
3+4+5=12 is more than 11
3+5+4=12 is more than 11
4+2+3=9 is less than 11
4+2+5=11 is equal to 11
4+3+2=9 is less than 11
4+3+5=12 is more than 11
4+5+2=11 is equal to 11
4+5+3=12 is more than 11
5+2+4=11 is equal to 11
5+3+4=12 is more than 11
5+4+2=11 is equal to 11
5+4+3=12 is more than 11