public class Main
{
static final int MAX_LENGTH = 13; // about the biggest that will fit into long, use BigInteger for bigger values
static long printValue
(String s
) {
long result = 0;
for (int i = 0; i < s.length(); i++)
result
+= (long)Math.
pow(27, MAX_LENGTH
- i
- 1)*(1 + s.
charAt(i
) - 'a'); System.
out.
printf("%-20s = %20d\n", s, result
); return result;
}
public static void main
(String[] args
) {
printValue("a");
printValue("aa");
printValue("aaa");
printValue("aaaa");
printValue("aaaaa");
printValue("abacus");
printValue("abbreviation");
printValue("account");
printValue("accuracy");
printValue("announcement");
printValue("z");
}
}
cHVibGljIGNsYXNzIE1haW4KewogICBzdGF0aWMgZmluYWwgaW50IE1BWF9MRU5HVEggPSAxMzsgLy8gYWJvdXQgdGhlIGJpZ2dlc3QgdGhhdCB3aWxsIGZpdCBpbnRvIGxvbmcsIHVzZSBCaWdJbnRlZ2VyIGZvciBiaWdnZXIgdmFsdWVzCiAgIHN0YXRpYyBsb25nIHByaW50VmFsdWUoU3RyaW5nIHMpCiAgIHsKICAgICAgbG9uZyByZXN1bHQgPSAwOwogICAgICBmb3IgKGludCBpID0gMDsgaSA8IHMubGVuZ3RoKCk7IGkrKykKICAgICAgICAgcmVzdWx0ICs9IChsb25nKU1hdGgucG93KDI3LCBNQVhfTEVOR1RIIC0gaSAtIDEpKigxICsgcy5jaGFyQXQoaSkgLSAnYScpOwogICAgICBTeXN0ZW0ub3V0LnByaW50ZigiJS0yMHMgPSAlMjBkXG4iLCBzLCByZXN1bHQpOwogICAgICByZXR1cm4gcmVzdWx0OwogICB9CiAgIAogICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKQogICB7CiAgICAgIHByaW50VmFsdWUoImEiKTsKICAgICAgcHJpbnRWYWx1ZSgiYWEiKTsKICAgICAgcHJpbnRWYWx1ZSgiYWFhIik7CiAgICAgIHByaW50VmFsdWUoImFhYWEiKTsKICAgICAgcHJpbnRWYWx1ZSgiYWFhYWEiKTsKICAgICAgcHJpbnRWYWx1ZSgiYWJhY3VzIik7CiAgICAgIHByaW50VmFsdWUoImFiYnJldmlhdGlvbiIpOwogICAgICBwcmludFZhbHVlKCJhY2NvdW50Iik7CiAgICAgIHByaW50VmFsdWUoImFjY3VyYWN5Iik7CiAgICAgIHByaW50VmFsdWUoImFubm91bmNlbWVudCIpOwogICAgICBwcmludFZhbHVlKCJ6Iik7CiAgIH0KfQ==