输入格式:
每个测试输入包含 1 个测试用例,即给出自然数 n 的值。这里保证 n 小于 1。
输出格式:
在一行内输出 n 的各位数字之和的每一位,拼音数字间有 1 空格,但一行中最后一个拼音数字后没有空格。
输入样例:
1234567890987654321123456789
输出样例:
yi san wu
#include<iostream> using namespace std; int main() { char ch; ch = getchar(); int sum = 0; while (ch!='\n') { switch (ch) { 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: break; } ch = getchar(); } //将结果存入result数组中 char* result[100]; int i=0;//数组下标 while (sum) { int x = sum % 10; switch (x) { case 0: result[i] = "ling"; break; case 1: result[i] = "yi"; break; case 2: result[i] = "er"; break; case 3: result[i] = "san"; break; case 4: result[i] = "si"; break; case 5: result[i] = "wu"; break; case 6: result[i] = "liu"; break; case 7: result[i] = "qi"; break; case 8: result[i] = "ba"; break; case 9: result[i] = "jiu"; break; default: break; } i++; sum = sum / 10; } //逆序输出数组 for (int j = i - 1; j >= 0; j--) { if (j == 0) { cout << result[j]; } else { cout << result[j] << " "; } } return 0; }