This repository has been archived on 2025-02-10. You can view files and clone it, but cannot push or open issues or pull requests.
Files
beopen/server/modules/algorithms/hash.cpp
2025-02-10 12:37:33 +00:00

23 lines
393 B
C++

# include<string.h>
# include<string>
# include<cmath>
typedef long long int Lint;
extern "C" Lint hash(char* str) {
Lint m = std::pow(10,7) + 7;
int p = 97;
Lint total = 0;
for (int i=0; i<strlen(str); i++) {
total += (int(str[i]) - 32) * pow(p,i);
}
Lint result = total % m;
return result;
}
extern "C" Lint printc(char* str) {
int num = strlen(str);
return num;
}