b593. Code
標籤 :
通過比率 : 178人/204人 ( 87% ) [非即時]
評分方式:
Tolerant

最近更新 : 2015-10-06 08:05

內容

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.

範例輸入 #1
bf 
abca 
vwxyz 
0
範例輸出 #1
55 
0
83681 
測資資訊:
記憶體限制: 64 MB
公開 測資點#0 (100%): 2.0s , <1K
提示 :
標籤:
出處:
[管理者: spocktsai (囧rz) ]

本題狀況 本題討論 排行

編號 身分 題目 主題 人氣 發表日期
28211 41075001H (茶トラ猫) b593
解題報告 C++
764 2021-11-18 19:27
18399 deron0506@gm ... (Deron Zheng) b593
想法
1920 2019-07-09 18:34