PAT (Basic Level) Practice 1002(中文)(C++)

#include <iostream>
using namespace std;

int main() {
    int a[101] = { 0 };//存储输入数据
    int i = 0;//后面循环使用
    int sum = 0;//数据各位之和
    int c;
    int b[10] = { 0 };//
    while ((c = getchar()) != '\n') {//逐个输入
        a[i++] = c - '0';
    }
    for (--i; i >= 0; --i) sum += a[i];
    ++i;
    while (sum) {
        b[i++] = sum % 10;
        sum /= 10;
    }
    for (--i; i >= 0; --i) {
        switch (b[i]) {
        case 0:cout << "ling";
            break;
        case 1:cout << "yi";
            break;
        case 2:cout << "er";
            break;
        case 3:cout << "san";
            break;
        case 4:cout << "si";
            break;
        case 5:cout << "wu";
            break;
        case 6:cout << "liu";
            break;
        case 7:cout << "qi";
            break;
        case 8:cout << "ba";
            break;
        default:cout << "jiu";
            break;
        }
        cout << " ";
    }
}

上一篇:PAT (Basic Level) Practice 1004(中文)(C++)


下一篇:PAT (Advanced Level) Practice甲级练习