Bangla numbers normally use ’kuti’ (10000000), ’lakh’ (100000), ’hajar’ (1000), ’shata’ (100) while expanding and converting to text. You are going to write a program to convert a given number to text with them.
Input
The input file may contain several test cases. Each case will contain a non-negative number ≤ 999999999999999.
Output
For each case of input, you have to output a line starting with the case number with four digits adjustment followed by the converted text.
Sample Input
23764
45897458973958
Sample Output
- 23 hajar 7 shata 64
- 45 lakh 89 hajar 7 shata 45 kuti 89 lakh 73 hajar 9 shata 58
问题链接:UVA10101 Bangla Numbers
问题简述:(略)
问题分析:
进制转换问题,但是需要考虑前导0的处理,后若干位均为0的处理。
给出的代码充分考虑的程序的通用性,递归的运用恰到好处。
程序说明:(略)
参考链接:(略)
题记:程序通用性是程序员的最高追求!
AC的C++语言程序如下:
/* UVA10101 Bangla Numbers */
#include <bits/stdc++.h>
using namespace std;
string key[] = {"kuti", "lakh", "hajar", "shata"};
long long weight[] = {10000000LL, 100000LL, 1000LL, 100LL};
const int N = sizeof(weight) / sizeof(long long);
void output(long long n)
{
bool flag = true;
for(int i = 0; i < N; i++) {
if(n >= weight[i]) {
flag = false;
output(n / weight[i]);
printf(" %s", key[i].c_str());
long long right = n % weight[i];
if(right) output(right);
break;
}
}
if(flag)
printf(" %lld", n);
}
int main()
{
int caseno = 0;
long long n;
while(~scanf("%lld", &n)) {
printf("%4d.", ++caseno);
if(n == 0)
printf(" 0");
else
output(n);
printf("\n");
}
return 0;
}