fork(18) download
  1. public class Main
  2. {
  3. static final int MAX_LENGTH = 13; // about the biggest that will fit into long, use BigInteger for bigger values
  4. static long printValue(String s)
  5. {
  6. long result = 0;
  7. for (int i = 0; i < s.length(); i++)
  8. result += (long)Math.pow(27, MAX_LENGTH - i - 1)*(1 + s.charAt(i) - 'a');
  9. System.out.printf("%-20s = %20d\n", s, result);
  10. return result;
  11. }
  12.  
  13. public static void main(String[] args)
  14. {
  15. printValue("a");
  16. printValue("aa");
  17. printValue("aaa");
  18. printValue("aaaa");
  19. printValue("aaaaa");
  20. printValue("abacus");
  21. printValue("abbreviation");
  22. printValue("account");
  23. printValue("accuracy");
  24. printValue("announcement");
  25. printValue("z");
  26. }
  27. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
a                    =   150094635296999136
aa                   =   155653695863554659
aaa                  =   155859586995649308
aaaa                 =   155867212593134295
aaaaa                =   155867495022670776
abacus               =   161447654121636750
abbreviation         =   161763445236432705
account              =   167509959568845180
accuracy             =   167554723653128382
announcement         =   230924421746611188
z                    =  3902460517721977536