码迷,mamicode.com
首页 > 其他好文 > 详细

UVa 10101 - Bangla Numbers

时间:2014-10-25 18:46:48      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:blog   io   os   ar   java   sp   on   2014   log   

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

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


UVa 10101 - Bangla Numbers

标签:blog   io   os   ar   java   sp   on   2014   log   

原文地址:http://blog.csdn.net/mobius_strip/article/details/40455085

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!