C/C++教程

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

本文主要是介绍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 1002(中文)(C++)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!