SHARE
TWEET

Untitled

a guest Jul 19th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #define MIN 10000
  4. using namespace std;
  5.  
  6. int hash2[MIN + 1] = { 0 };
  7. int count = 0;
  8.  
  9. void readData()
  10. {
  11.     ifstream fin("2sum.txt");
  12.     int temp = 0;
  13.     while(fin>>temp)
  14.     {
  15.         if(temp < MIN)
  16.             hash2[temp]++;
  17.     }
  18. }
  19.  
  20. bool hashMap(int n)
  21. {
  22.     if(n > MIN)
  23.         return false;
  24.     if(hash2[n])
  25.         return true;
  26.     else
  27.         return false;
  28. }
  29.  
  30. int main()
  31. {
  32.     readData();
  33.  
  34.     for(int i = -10000; i <= 10000; i++)
  35.     {
  36.         for(int j = -10000; j <= 10000; j++)
  37.         {
  38.             if(hashMap(j) && hashMap(i - j))
  39.             {
  40.                 count++;
  41.                 break;
  42.             }
  43.         }
  44.     }
  45.     cout<<count<<endl;
  46.     return 0;
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top