Full completed project
This commit is contained in:
22
server/modules/algorithms/hash.cpp
Normal file
22
server/modules/algorithms/hash.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
# 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;
|
||||
}
|
||||
Reference in New Issue
Block a user