c_cpp uva10101

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp uva10101相关的知识,希望对你有一定的参考价值。

#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

string bangla(uint64_t num)
{
    if (num == 0) return "0";

    struct Unit
    {
        uint64_t base;
        string name;
    };
    static const vector<Unit> units =
    {
        { 100, ""      },
        { 10,  "shata" },
        { 100, "hajar" },
        { 100, "lakh"  },
    };

    vector<string> text;

    while (true)
    {
        for (const auto& unit : units)
        {
            auto remain = num%unit.base;
            num /= unit.base;

            if (remain > 0)
            {
                text.push_back(unit.name);
                text.push_back(to_string(remain));
            }
        }

        if (num == 0) break;
        text.push_back("kuti");
    }

    return accumulate(text.rbegin() + 1, text.rend(), text.back(), [](const string& init, const string& s)
    {
        return init + (s.empty() ? "" : " " + s);
    });
}

int main()
{
    size_t case_num = 1;

    uint64_t num;
    while (cin >> num)
    {
        cout << setw(4) << case_num++ << ". " << bangla(num) << endl;
    }

    return 0;
}

以上是关于c_cpp uva10101的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp uva10093

c_cpp uva12307

c_cpp uva681

c_cpp uva10107

c_cpp uva591

c_cpp uva12015