Problem Description:
Special strings are often encoded in data encryption and data compression. The given Alphabet a consists of 26 lowercase English letters, which is a={a,b...z}. The long-order string produced by the alphabet is the order in which the letters appear from left to right in the specified string, in the same order as the letters appear in the alphabet. And a maximum of 1 occurrences per character. For example, a,b,ab,bc,xyz, such as strings, are ascending strings. Now, all ascending strings that are not more than 6 of the length of the alphabet A are encoded in the dictionary as follows: A (1), B (2), C (3) ..., AB (27 ), AC (,..................)
For an ascending string of any length not exceeding 6, the code in the above dictionary is calculated quickly.
Algorithm analysis: such as the code, thinking, such as Egh, we first put only a long case and two-bit long add up, that is, 26C1 and 26c2, and then find the starting bit of a,b,c,d three-bit words, they are also ranked before EFG, that is 25C2,24C2,23C2 , 22C2 (note here is not 26c2, because if you start with a, then the next two bits can only be selected from the number after B, that is, 25, B starts with 24 and so on), and then consider the beginning of E, because in the above case is the high after the beginning of the case of E, this time need to note, Eah, EBH This is not reasonable, so we want to compare Getp (buffer[i],size-i,buffer[i-1]-' a ' + 1), Buffer[i] and buffer[i-1] to compare E and G and then by comparing only the EF to the beginning of the reasonable, Then we calculate from EFA to EFZ, then to the last one because of the non-existence of EGA,EGB (through the comparison of buffer), so there is no other case in the beginning of the eg, that is, the Egh is the first case of the three digits of the eg, at this time our positioning work is finished.
Dictionary order Problems