Learning Chinese characters is not an easy task. The list of characters in common use by the Ministry of Education alone contains 4808 characters, not to mention the even rarer ones in the Kangxi Dictionary. Even native speakers might sometimes run into an unknown character. This is why people tried to come up with different ways to represent the sounds of the characters. In modern times, there are two major methods to do this: Zhuyin Fuhao (注音符號) and Hanyu Pinyin (漢語拼音), with the former being widespread among Taiwanese and the latter among foreigners.
Figure 1: Zhuyin Fuhao onsets (聲母) and their Pinyin counterparts. The grayed-out ones are not used in modern Mandarin.
Figure 2: Zhuyin Fuhao finals (韻母) and their Pinyin counterparts.
When Chinese characters are ordered by Zhuyin Fuhao, the onset is to be considered first. The order goes b ㄅ, p ㄆ, m ㄇ, f ㄈ... z ㄗ, c ㄘ, s ㄙ, and, lastly, those without an onset. If the onset is the same, they are ordered by the medial vowel: i ㄧ, u ㄨ, ü ㄩ, and lastly the main vowel and the coda: a ㄚ, o ㄛ, e ㄜ, ê ㄝ, ai ㄞ, ei ㄟ, ao ㄠ, ou ㄡ, an ㄢ, en ㄣ, ang ㄤ, and eng ㄥ.
As for the Pinyin system, each character is transcribed using the Latin alphabet. The rules are:
1. If the onset is present, the syllable is typically formed by combining the onset and the final.
清(ㄑㄧㄥ) is written as qing
2. If the onset is present, and the final is iou, uei, uen, or ueng, the final will be written as -iu, -ui, -un, and -ong respectively.
牛(ㄋㄧㄡˊ) is written as niu rather than *niou
3. If the onset is j ㄐ, q ㄑ, or x ㄒand the final starts with ü, the final will be written with u instead.
學(ㄒㄩㄝˊ) is written as xue rather than *xve or *xüe (Since ü is not an ASCII character, v is often used instead.)
4. When the onset is not present, the letters i and u at the beginning of the final will change to y and w, respectively, unless it is the sole vowel in the final, where the letter would be appended at the beginning.
我(ㄨㄛˇ) is written as wo rather than *uo.
五(ㄨˇ ) is written as wu rather than *u.
5. When the onset is not present, the letters ü at the front of the final will always change to yu.
元(ㄩㄢˊ ) is written as yuan rather than *üan or *van.
6. If the second syllable has no onset nor medial vowel (i.e., it starts with a, o, or e), an apostrophe ' should be used before the syllable if the lack results in ambiguity.
西安(ㄒㄧ ㄢ) is written as xi'an as opposed to 先 (ㄒㄧㄢ) xian.
命案(ㄇㄧㄥˋ ㄢˋ ) is written as ming'an as opposed to 敏感 (ㄇㄧㄣˇ ㄍㄢˇ) mingan
In this task, you must sort the names written in Pinyin based on the Zhuyin order. For example, if the names in the list are:
Chinese Name | Zhuyin Transcription | Pinyin Romanization |
---|---|---|
胡敏君 | ㄏㄨˊ ㄇㄧㄣˇ ㄐㄩㄣ | Hú Mǐnjūn |
景璞 | ㄐㄧㄥˇ ㄆㄨˊ | Jǐng Pú |
蕭澤然 | ㄒㄧㄠ ㄗㄜˊ ㄖㄢˊ | Xiāo Zérán |
莊景堯 | ㄓㄨㄤ ㄐㄧㄥˇ ㄧㄠˊ | Zhuāng Jǐngyáo |
歐偉興 | ㄡ ㄨㄟˇ ㄒㄧㄥ | Ōu Wěixīng |
徐美妮 | ㄒㄩˊ ㄇㄟˇ ㄋㄧˊ | Xú Měiní |
曾恩傑 | ㄗㄥ ㄣ ㄐㄧㄝˊ | Zēng Ēnjié |
高敦晉 | ㄍㄠ ㄉㄨㄣ ㄐㄧㄣˋ | Gāo Dūnjìn |
許木羽 | ㄒㄩˇ ㄇㄨˋ ㄩˇ | Xǔ Mùyǔ |
鄭敦謙 | ㄓㄥˋ ㄉㄨㄣ ㄑㄧㄢ | Zhèng Dūnqiān |
The output will be ordered as:
Chinese Name | Zhuyin Transcription | Pinyin Romanization |
---|---|---|
高敦晉 | ㄍㄠ ㄉㄨㄣ ㄐㄧㄣˋ | Gāo Dūnjìn |
胡敏君 | ㄏㄨˊ ㄇㄧㄣˇ ㄐㄩㄣ | Hú Mǐnjūn |
景璞 | ㄐㄧㄥˇ ㄆㄨˊ | Jǐng Pú |
蕭澤然 | ㄒㄧㄠ ㄗㄜˊ ㄖㄢˊ | Xiāo Zérán |
徐美妮 | ㄒㄩˊ ㄇㄟˇ ㄋㄧˊ | Xú Měiní |
許木羽 | ㄒㄩˇ ㄇㄨˋ ㄩˇ | Xǔ Mùyǔ |
鄭敦謙 | ㄓㄥˋ ㄉㄨㄣ ㄑㄧㄢ | Zhèng Dūnqiān |
莊景堯 | ㄓㄨㄤ ㄐㄧㄥˇ ㄧㄠˊ | Zhuāng Jǐngyáo |
曾恩傑 | ㄗㄥ ㄣ ㄐㄧㄝˊ | Zēng Ēnjié |
歐偉興 | ㄡ ㄨㄟˇ ㄒㄧㄥ | Ōu Wěixīng |
Don't worry: you aren't going to write the comparing function and the whole sorting algorithm yourself. You only have to implement two functions, one to swap two strings and one to partition the string between the index l and r (inclusively), as well as return the index of the partition pivot. You are given a comparing function int compareByZhuyin(const char* str1, const char* str) which returns a negative value when str1 should come before str2, a positive value when str2 should come before str1, and zero when both strings are equal.
The first line contains an integer N, specifying how many names are in the list.
The next N lines are the names that you want to sort, written in Pinyin system with tones omitted.
The sorted list of name, based on Zhuyin order.