Advertisement
thornik

Bench 'Hash' for VC++

Dec 5th, 2017
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. // cl.exe /EHsc /Ox hash.cpp
  2. #include <iostream>
  3. #include <string>
  4. #include <unordered_map>
  5. #include <stdlib.h>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12.     int n = ((argc == 2) ? atoi(argv[1]) : 1);
  13.     unordered_map<string, int> X;
  14.    
  15.     char hexString[20];
  16.    
  17.     for (int i=1; i<=n; i++) {
  18.         itoa(i, hexString, 16);
  19.         X[ strdup(hexString) ] = i;
  20.     }
  21.    
  22.     int c = 0;
  23.     for (int i=n; i>0; i--) {
  24.         if (X.find(to_string(i)) != X.end()) c++;
  25.     }
  26.  
  27.     cout << c << endl;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement