1002

作者: 峡迩 | 来源:发表于2017-07-13 22:03 被阅读0次

    部分正确?

    #include<iostream>
    #include<vector>
    #include<string>
    using namespace std;
    
    int main()
    {
        vector<string> 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<int>(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

          本文链接:https://www.haomeiwen.com/subject/anmghxtx.html