题目:将数字数转化成数字加单词的表示形式输出。
分析:数论。简单题。直接分成两部分除10000000的商和余数,分别输出就可以。
说明:注意输入为数字0的情况,还有long long类型防止溢出。
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
void output(long long a)
{
if (a >= 10000000LL) {
output(a/10000000LL);
printf(" kuti");
output(a%10000000LL);
}else {
if (a >= 100000LL)
cout << " " << (a/100000LL) << " lakh";
a %= 100000LL;
if (a >= 1000LL)
cout << " " << (a/1000LL) << " hajar";
a %= 1000LL;
if (a >= 100LL)
cout << " " << (a/100LL) << " shata";
a %= 100LL;
if (a > 0LL)
cout << " " << a;
}
}
int main()
{
int t = 1;
long long n;
while (cin >> n) {
printf("%4d.",t ++);
output(n);
if (n == 0LL)
printf(" 0");
printf("\n");
}
return 0;
}