UVa 10101 - Bangla Numbers

来源:互联网 发布:罗志祥人气数据 编辑:程序博客网 时间:2024/06/04 00:41

题目:将数字数转化成数字加单词的表示形式输出。

分析:数论,简单题。直接分成两部分除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;}


0 0
原创粉丝点击