6 kyu

T.T.T.24: Chinese surname (《百家姓》)

Description:

Story

Chinese people have a lot of surnames. In ancient China, there is a children's book, called 《百家姓》(Hundred Family Surnames). Of course, this book contains not just one hundred surnames, but a total of 504 surnames, which are the most common surnames in China.

surnames

In ancient times, Chinese children learn by reciting the book. They recite the book like a poem:

赵钱孙李,周吴郑王。
冯陈褚卫,蒋沈韩杨。
.......
.......

Some of the children to show that they are smarter, they will recite the book in reverse:

......
......
杨韩沈蒋,卫褚陈冯。
王郑吴周,李孙钱赵。

Task

Complete the function that accepts a string surnames which contains some surnames, you should reverse them and return a string in accordance with the following rules.

Rules

  1. The output string should add a Chinese comma ","in the back of the 4th Chinese characters, and adding a Chinese period "。" in the back of the 8th Chinese characters.

    "赵钱孙李周吴郑王"
    // ---reverse the order and add comma and period---
    // should return
    "王郑吴周,李孙钱赵。"
    
  2. Most of the Chinese people's surnames are 1 Chinese character, but there are a few people whose surnames are 2 Chinese characters. The surname of 2 Chinese characters should be read as a whole and not be reversed. All of these special surnames have been saved in the variable special (already preloaded).

    "万俟司马上官欧阳" 
    // 万俟,司马,上官,欧阳 are special surnames
    // ---reverse the order and add comma and period---
    // should return
    "欧阳上官,司马万俟。"
    

    If there are multiple matches, you should group the earliest appearances of special surnames first.

  3. If the string length is more than 8, it needs to be split into multiple lines. You can assume that all the string parameters are multiples of 8.

    "赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨"
    // ---reverse the order and add comma and period---
    // should return
    "杨韩沈蒋,卫褚陈冯。\n王郑吴周,李孙钱赵。"
    
Puzzles
Games

Stats:

CreatedAug 9, 2016
PublishedAug 9, 2016
Warriors Trained200
Total Skips2
Total Code Submissions330
Total Times Completed67
JavaScript Completions67
Total Stars9
% of votes with a positive feedback rating94% of 24
Total "Very Satisfied" Votes21
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes0
Total Rank Assessments6
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • kazk Avatar
  • Voile Avatar
  • Just4FunCoder Avatar
Ad