Title Link: http://acm.swust.edu.cn/problem/0552/
Time limit (ms): $ Memory Limit (KB): 65535 Description
Count the Money ~ ~ ~ Enter a number, less than 999999999999, we need to convert them to pinyin, we stipulate for example 1234000567 of the read as "1,234,000,567" specifically see the input and output
Input
A number n
Output
Numbers plus pinyin, see sample OUTPUT
Sample Input
9999999999991234560001234000567 |
Sample Output
9qian9bai9shi9yi9qian9bai9shi9wan9qian9bai9shi91yi2qian3bai4shi5wan6qian1shi2yi3qian4baiwanling5bai6shi7 |
scpc--しιしιπ
problem-solving ideas: This is all done tonight (the brain is completely chaotic), that is, the number is entered as a string, and then reversed, with this character array
string p[] = {"", "Shi", "Bai", "Qian", "wan", "Shi", "Bai", "Qian", "Yi", "Shi", "Bai", "Qian"}; match, the focus is to pay attention to the processing of multiple zeros , watch the Code ~ ~The code is as follows:
1#include <iostream>2#include <string>3 using namespacestd;4 intar[ the], Len;5 Long LongN;6 stringS,p[] = {"","Shi","Bai","Qian","Wan","Shi","Bai","Qian","Yi","Shi","Bai","Qian" };7 voidChange () {8 Reverse (S.begin (), S.end ());9 intI, flag =0;Ten for(i = s.size ()-1; I >=0;){ One if(s[i]-'0'){ AFlag =0; -cout << S[i] <<P[i]; -i--; the } - Else{ - //two conditions cannot swap position if it is 6000, the last i=-1,s[-1] Unreachable (Runtime error once) - while(i>=0&&! (s[i]-'0')){ + if(! I4) &&!flag) { -Flag =1; +cout <<P[i]; A } ati--; - } - if(I >=0) cout <<"Ling"; - } - } -cout <<Endl; in } - to intMain () { + while(cin>>s) - Change (); the return 0; *}
View Code
[Swust OJ 552]--Pinyin Teaching (law-seeking)