-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash.cpp
More file actions
47 lines (35 loc) · 871 Bytes
/
hash.cpp
File metadata and controls
47 lines (35 loc) · 871 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
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<iostream>
#include<fstream>
#include<map>
using namespace std;
map<int,int> mp;
void HashMap(int arr[], int size) {
for(int i = 0 ; i < size ; i++) {
mp[arr[i]] = i+1;
}
}
string findSum(int arr[], int size , int target) {
for(int i = 0 ; i < size ; i++) {
int complement = target - arr[i];
if(mp[complement]) {
return "1";
}
}
return "0";
}
int main() {
int arr[100000];
ifstream inp("HashInt.txt");
int count = 0 , x;
while(count < 100000 && inp >> x) {
arr[count++] = x;
}
inp.close();
HashMap(arr,100000);
int targetSum[9] = {231552, 234756, 596873, 648219, 726312, 981237, 988331, 1277361, 1283379};
string output = "";
for(int i = 0 ; i < 9 ; i++) {
output += findSum(arr, 100000, targetSum[i]);
}
cout << output;
}