forked from matthewsamuel95/ACM-ICPC-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsum_pair.cpp
More file actions
33 lines (25 loc) · 693 Bytes
/
sum_pair.cpp
File metadata and controls
33 lines (25 loc) · 693 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
#include <bits/stdc++.h>
using namespace std;
void printPairs(int arr[], int arr_size, int sum)
{
unordered_set<int> s;
for (int i = 0; i < arr_size; i++)
{
int temp = sum - arr[i];
if (temp >= 0 && s.find(temp) != s.end())
cout << "Pair with given sum " << sum <<
" is (" << arr[i] << ", " << temp <<
")" << endl;
s.insert(arr[i]);
}
}
/* Driver program to test above function */
int main()
{
int A[] = {1, 4, 45, 6, 10, 8};
int n = 16;
int arr_size = sizeof(A)/sizeof(A[0]);
// Function calling
printPairs(A, arr_size, n);
return 0;
}