Advertisement
rahat62

Hasting string

May 9th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int has(string s,long long int mod,long long int base)
  5. {
  6.     int value =0;
  7.     for(int i=0;i<s.size();i++)
  8.     {
  9.         value = ( (value * base) + (s[i] - 'A' + 1) ) % mod;
  10.  
  11.  
  12.     }
  13.      return value;
  14.  
  15. }
  16.  
  17. int main()
  18. {
  19.  
  20.     string s;
  21.     long long int m,b;
  22.     cin>>s;
  23.     cin>>m>>b;
  24.  
  25.     cout<<has(s,m,b);
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement