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.