1082 Read Number in Chinese (25分) | 您所在的位置:网站首页 › 808080808=1 › 1082 Read Number in Chinese (25分) |
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 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 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
题解: 这题真的很麻烦 思路: 按照中文方式把数字分节,4位为一节,输出规则相同 几千几百几十几。 如 123456789: 1 (亿节) 2345 (万节) 6789 (个节) 、 两个指针left 和 right 分别指向每节的起始和结束位置 之后就需要考虑如何处理零和空格这些细节问题 设置标志位flag判断是否需要输出ling
给个例子:808080808:ba yi ling ba bai ling ba wan ling ba bai ling ba 800000008 :ba yi ling ba不要输出成 ba yi wan ling ba 所以需要再来一个标志位isPrint,标志是否输出过位,来避免该问题 。 #include #include using namespace std; string num[10] = { "ling","yi","er","san","si","wu","liu","qi","ba","jiu" }; string c[5]{ "Shi","Bai","Qian","Wan","Yi" }; int main() { string str; cin >> str; int size, left = 0, right = str.size() - 1; size = str.size(); if (str[0] == '-') { cout |
CopyRight 2018-2019 实验室设备网 版权所有 |