Dictionary order Problems

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.