#include #include #include #include #include #include using namespace std; std::unordered_set> get_triple(int A, std::vector& x) { std::unordered_set history; std::sort(x.begin(), x.end()); std::unordered_set> triples; for (int i = 0; i < x.size(); i++) { for (int j = i + 1; j < x.size(); j++) { int target = A - x[i] - x[j]; if (history.find(target) != history.end()) { std::vector triple = { target, x[i], x[j] }; triples.insert(triple); } } history.insert(x[i]); } return triples; } int main() { ifstream fin("input.txt"); int a = 10; std::vector vec{ 5,2,8,1,1,3,4,4 }; std::unordered_set> result = get_triple(a, vec); for (auto& triple : result) { for (auto element : triple) { cout << element << " "; } cout << endl; } }