Bangla Numbers
#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;
}