C/C ++ skills review exams for a company X

Source: Internet
Author: User

Question: A string collation

The host name is composed of multi-level domain names, from the right to the left, followed by top-level domain names, second-level domain names, third-level domain names ..... And so on For example, Host Name: Google.com.hkHK is top-level domain name COM is second-level domain name Google is third-level domain name now we need to implement a host name sorting Function Sorting rules1) The host names are sorted by domain name level, that is, the top-level domain names are sorted first, the top-level domain names are the same, and the top-level and second-level domain names are sorted by third-level domain names, and so on, until the entire host name is sorted 2) if the short host name is composed of one or more consecutive long host names starting from the top-level domain name, the short host name is placed before the long host name. For example, Google.com is placed before gmail.google.com. 3) each level of domain name is ordered alphabetically. For the definition of the dictionary order, see the next page. Input to ensure that the following rules are met (no check required)1) The host name is given as a string, not an empty string. 2) The host name only contains lowercase letters and delimiters '. '3) The host name does not contain consecutive '. ', not '. 'Neither start '. 'End 3) The host name does not exist.

Definition of dictionary order

1. Two words (letters in the order from left to right) are first sorted by the first letter as the benchmark. If the first letter is the same, the second letter is used as the benchmark, if the second letter is the same, the third letter is used as the benchmark. If a letter is not the same, the word in the First Order is in the first order. For example, ABC is placed before abf. 2. If a short word is a continuous part of a long word starting from the first letter, the short word is ordered first. For example, ABC is placed before ABCD. ExampleAfter adding the following domain names in sequence, sort them according to the rules, and then click wei.comimail.w.wei.com google.com.hkteltalk.org. the domain names in the last 4th locations after sorting are google.com.hk.

Related Article

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.