-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathCS_4_PairSum.cpp
More file actions
34 lines (33 loc) · 779 Bytes
/
Copy pathCS_4_PairSum.cpp
File metadata and controls
34 lines (33 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
int main()
{
vector<int> arr = {1, 2, 3, 4, 5};
int s = 5;
vector<vector<int>> ans;
for (int i = 0; i < arr.size() - 1; i++)
{
for (int j = i + 1; j < arr.size(); j++)
{
if (arr[i] + arr[j] == s)
{
vector<int> temp;
temp.push_back(min(arr[i], arr[j]));
temp.push_back(max(arr[i], arr[j]));
ans.push_back(temp);
}
}
}
sort(ans.begin(), ans.end());
cout << "Answer: " << endl;
for (auto &vector : ans)
{
for (auto &vectorElem : vector)
{
cout << vectorElem << ' ';
}
cout << endl;
}
}