Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <unordered_set>
- #include <algorithm>
- using namespace std;
- std::unordered_set<std::vector<int>> get_triple(int A, std::vector<int>& x) {
- std::unordered_set<int> history;
- std::sort(x.begin(), x.end());
- std::unordered_set<std::vector<int>> 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<int> 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<int> vec{ 5,2,8,1,1,3,4,4 };
- std::unordered_set<std::vector<int>> result = get_triple(a, vec);
- for (auto& triple : result) {
- for (auto element : triple) {
- cout << element << " ";
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement