Pat Problem Solving report [1082]

Source: Internet
Author: User

1082. Read number in Chinese (25) Time Limit 400 MS
The memory limit is 32000 kb.
Code length limit: 16000 B
Question determination procedure Standard Author: Chen, Yue

Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. output "Fu" first if it is negative. for example,-123456789 is read as "Fu Yi er Qian San Bai Si Shi Wu Wan Liu Qian Qi Bai Ba Shi JIU ". note: zero ("Ling") must be handled correctly according to the Chinese tradition. for example, 100800 is "Yi Shi Wan Ling Ba bai ".

Input specification:

Each input file contains one test case, which gives an integer with no more than 9 digits.

Output specification:

For each test case, print in a line the Chinese way of reading the number. The characters are separated by a space and there must be no extra space at the end of the line.

Sample input 1:
 
-123456789
Sample output 1:
 
Fu Yi er Qian San Bai Si Shi Wu Wan Liu Qian Qi Bai Ba Shi JIU
Sample input 2:
 
100800
Sample Output 2:
 
Yi Shi Wan Ling Ba Bai
Simple simulation, but the process description is a bit cool. Note: zero ("Ling") must be handled correctly according to the Chinese tradition what is Chinese tradition is actually a special processing for 0. [1] The tail 0 does not pronounce [2] multiple consecutive 0, only one sound [3] multiple discontinuous 0, all must be pronounced [4] More than four digits must be sent to the WAN sound [5] More than eight digits must be sent to Yi sound and there is a rule: shi Bai Qian appears. AC code:
// Pat-1082.cpp: defines the entry point for the console application. // # Include "stdafx. H "# include" iostream "# include" string "# include" algorithm "# include" vector "# include" stack "using namespace STD; stack <string> ans; string num [] = {"Ling", "Yi", "er", "San", "Si", "Wu", "Liu", "Qi ", "Ba", "Jiu"}; string POS [] = {"Shi", "bai", "Qian", "Wan", "Yi"}; int main () {long int n = 0; bool firstout = true; CIN> N; If (n = 0) {cout <"Ling"; goto end ;} if (n <0) {cout <"Fu"; firstout = false; n =- (N) ;}int CNT = 0; bool wan_flag = false; bool zero = false; bool first = true; while (n) {int temp = n % 10; // 0 special processing if (temp = 0) {If (CNT = 3) {wan_flag = true;} n/= 10; If (! First) {CNT ++;} First = false; If (zero) // the first occurrence of 0 {ans. push (Num [0]); zero = false; continue;} else {continue;} zero = true; If (first) // ignore single position {ans. push (Num [temp]); // Yi er San Si ~~~~~ N/= 10; first = false; continue;} If (CNT <7) {If (wan_flag) {wan_flag = false; ans. push (Pos [3]);} ans. push (Pos [CNT % 4]); // Shi Bai Qian Wan} else {ans. push (Pos [4]); // Yi} ans. push (Num [temp]); // Yi er San Si ~~~~~ N/= 10; CNT ++;} while (! Ans. empty () {string temp = ans. top (); ans. pop (); If (firstout) {firstout = false; cout <temp; continue;} cout <"<temp;} end: Return 0 ;}

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.