fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static int hashCode(char[] key, int HASH_SIZE)
  11. {
  12. // write your code here
  13. long q=1;
  14. long result=0;
  15. int len=key.length;
  16. for(int i=len-1;i>-1;i--)
  17. {
  18. result=result+key[i]*q;
  19. q=q*33;
  20. }
  21. result= result % (long)HASH_SIZE;
  22. return (int) result;
  23. }
  24. public static void main (String[] args) throws java.lang.Exception
  25. {
  26. // your code goes here
  27. int i = hashCode("ubuntu".toCharArray(), 1007);
  28. System.out.println(i);
  29. }
  30. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
549