Advertisement
Ne-Biolog

Untitled

Mar 29th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <memory.h>
  4. #include <iterator>
  5. #include <cassert>
  6. #include <fstream>
  7. #include <iomanip>
  8. #include <cstdlib>
  9. #include <bitset>
  10. #include <vector>
  11. #include <cstdio>
  12. #include <string>
  13. #include <queue>
  14. #include <deque>
  15. #include <cmath>
  16. #include <ctime>
  17. #include <stack>
  18. #include <set>
  19. #include <map>
  20.  
  21. using namespace std;
  22.  
  23. //#define int long long
  24.  
  25. #define fi first
  26. #define se second
  27. #define pb push_back
  28. #define mp make_pair
  29. #define all(x) x.begin() , x.end()
  30.  
  31. typedef long long ll;
  32. typedef long double ld;
  33. typedef pair < ll , ll > pll;
  34. typedef pair < int , int > pii;
  35.  
  36. template < typename T >
  37. T read(){
  38. T p = 1 , x = 0;
  39. char s = getchar();
  40. while(s == ' ' || s == '\n') s = getchar();
  41. if(s == '-') p = -1 , s = getchar();
  42. while(s >= '0' && s <= '9'){
  43. x = x * 10 + s - '0';
  44. s = getchar();
  45. }
  46. return x * p;
  47. }
  48.  
  49. template < typename A , typename B >
  50. void Umax(A &a , const B &b){
  51. if(a < b)
  52. a = b;
  53. }
  54.  
  55. template < typename A , typename B >
  56. void Umin(A &a , const B &b){
  57. if(a > b){
  58. a = b;
  59. }
  60. }
  61.  
  62. ll bin_pow (ll a , ll n) {
  63. if(n == 0){
  64. return 1;
  65. }
  66. if(n % 2 == 1){
  67. ll cnt = a * bin_pow(a , n - 1);
  68. return cnt;
  69. }
  70. else {
  71. ll cnt = bin_pow(a , n / 2);
  72. return cnt * cnt;
  73. }
  74. }
  75.  
  76. const int N = (int) 1e5 + 10;
  77. const int MOD = (int) 1e9 + 7;
  78. const int INF = (int) 1e9 + 10;
  79. const ll LLINF = (ll) 1e18 + 10;
  80. const int dx [] = { 0 , 0 , 1 , -1 };
  81. const int dy [] = { 1 , -1 , 0 , 0 };
  82.  
  83. class HashTable {
  84. public:
  85. HashTable(){}
  86. string find(const string& key);
  87. string remove(const string& key);
  88. string genStr(size_t len);
  89. int getHash(const string& str);
  90. void insert(const string& key, const string& value);
  91. private:
  92. };
  93.  
  94. string HashTable::genStr(size_t len) {
  95. string newStr = "";
  96. while(len--) {
  97. newStr += static_cast<char>(rand() % 26 + 'a');
  98. }
  99. return newStr;
  100. }
  101.  
  102. int HashTable::getHash(const string& str) {
  103. int value = 0;
  104. for(size_t i = 0; i < str.size(); ++i) {
  105. value = (value * 17 + str[i]) % 1597;
  106. }
  107. return value;
  108. }
  109.  
  110.  
  111. set<int> all;
  112.  
  113. int main ()
  114. {
  115. freopen("input.txt" , "r" , stdin);
  116. freopen("output.txt" , "w" , stdout);
  117. ios_base::sync_with_stdio(false);
  118.  
  119. srand(time(NULL));
  120. for(int i = 0; i < 100; ++i) {
  121. string z = HashTable.genStr(6);
  122. int h = HashTable.getHash(z);
  123. all.insert(h);
  124. }
  125.  
  126.  
  127. cout << all.size() << endl;
  128.  
  129.  
  130. return 0;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement