b593: Code

Transmitting and memorizing information is a task that requires different coding systems for the best use of the available space. A well-known system is that one where a number is associated to a character sequence. It is considered that the words are made only of lower case letters of English alphabet a, b, c, . . . , z (26 characters). Assume that we consider the words in which each letter is used at most once. The coding system works like this:

1. For a n-letter word w = w1w2 . . . wn, here wi denotes a letter for i = 1, 2, . . . , n, the letter wi = wj for all i = j and the order of wi precedes the order of wj in alphabetical order if i < j.

2. The words are arranged in the increasing order of their length.

3. The words with the same length are arranged in lexicographical order.
4. We code these words by integers, starting with a. Hence, these words are coded as follows: a -> 1, b -> 2, . . ., z -> 26, ab -> 27, . . ., az -> 51, bc -> 52, . . ., vwxyz -> 83681, . . ., and so no.

Write a program to specify the number for a given word if it can be coded according to this coding system.

The input data consists of several test cases. Each test case has one line that contains a word. The word has the following constraints:

1. The maximum length of a word is 26.
1. The word only uses 26 characters of English alphabet.

The number 0 indicates the end of the input data.

The output of each test case should be in one line. The output contains the code of the given word, or 0 if the word cannot be coded.

bf
abca
vwxyz
0


55
0
83681


[編輯：
(囧rz)
]

 編號 身分 題目 主題 人氣 發表日期 沒有發現任何「解題報告」