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:
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.
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:
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
編號 | 身分 | 題目 | 主題 | 人氣 | 發表日期 |
28211 | 41075001H (茶トラ猫) | b593 | 967 | 2021-11-18 19:27 | |
18399 | deron0506@gm ... (Deron Zheng) | b593 | 2060 | 2019-07-09 18:34 |