1002

部分正确?

#include
#include
#include
using namespace std;

int main()
{
    vector format_numbers{ "ling","yi","er","san","si","wu","liu","qi","ba","jiu" };

    string n = "3";
    //cin >> n;
    unsigned short sum = 0;
    for (auto &r : n)
    {
        sum = sum + static_cast(r) - 48;
    }
    cout << sum << endl;
    string out;

    if (0 == sum)
    {
        out = string(format_numbers[0]);
    }
    else
    {
        while (sum % 10)
        {
            if (0 == out.length())
                out = string(format_numbers[sum % 10]);
            else
                out = string(format_numbers[sum % 10]) + " " + out;
            sum = sum / 10;
        }
    }
    cout << out;

    cin.ignore();
    return 0;
}

你可能感兴趣的:(1002)