Zanjo_Betchi

Untitled

Aug 6th, 2018
35
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. void findPair(int arr[], int length,int key){
  4.     int temp;
  5.     map<int,int>hashMap;
  6.     for(int i =0;i<length;i++){
  7.         temp = (arr[i] - key) >= 0 ?(arr[i] - key):(arr[i] + key);
  8.         if(hashMap[temp]>0){
  9.             cout << arr[i] <<" "<<temp<<endl;
  10.         }
  11.         hashMap[arr[i]]++;
  12.     }
  13. }
  14. int main(){
  15.     int arr[] = {4,2,5,8,21,34,10}, key =24, length = sizeof(arr)/sizeof(arr[0]);
  16.     findPair(arr,length,key);
  17.     return 0;
  18. }
RAW Paste Data