标签:include class out == turn getline case nbsp system
读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
输入格式:每个测试输入包含1个测试用例,即给出自然数n的值。这里保证n小于10100。
输出格式:在一行内输出n的各位数字之和的每一位,拼音数字间有1 空格,但一行中最后一个拼音数字后没有空格。
输入样例:
1234567890987654321123456789
输出样例:
yi san wu
#include <iostream> #include <iomanip> #include <math.h> #include <stdio.h> #include <string> using namespace std; int main() { string give; getline(cin, give); int sum = 0; for (string::iterator it = give.begin(); it != give.end(); it++) { switch (*it) { case‘0‘:sum += 0; break; case‘1‘:sum += 1; break; case‘2‘:sum += 2; break; case‘3‘:sum += 3; break; case‘4‘:sum += 4; break; case‘5‘:sum += 5; break; case‘6‘:sum += 6; break; case‘7‘:sum += 7; break; case‘8‘:sum += 8; break; case‘9‘:sum += 9; break; default:; } } string bit[99]; int cnt = 0;//sum的位数 while (sum) { int temp = sum % 10; sum /= 10; switch (temp) { case 0:bit[cnt] = "ling"; break; case 1:bit[cnt] = "yi"; break; case 2:bit[cnt] = "er"; break; case 3:bit[cnt] = "san"; break; case 4:bit[cnt] = "si"; break; case 5:bit[cnt] = "wu"; break; case 6:bit[cnt] = "liu"; break; case 7:bit[cnt] = "qi"; break; case 8:bit[cnt] = "ba"; break; case 9:bit[cnt] = "jiu"; break; default:; } cnt ++; } int flag = 1; for (int i = cnt - 1; i >= 0; i--) { if (flag == 1) { cout << bit[i]; flag = 0; } else cout <<" "<< bit[i]; } system("pause"); return 0; }
标签:include class out == turn getline case nbsp system
原文地址:http://www.cnblogs.com/brightz2017/p/6580421.html