杭电oj1727(Hastiness)

杭电oj1727(Hastiness)

Problem Description

How many problems did you AC?
When you read this problem, don’t hasty and careless, this is also simple, haha, I didn’t cheat you.
The game over soon, WisKey starts using English begin countdown. He not only have no gene in math, but also bad in English. Fortunately, He met you who have gift in programming. So please help him to translate.

Input

Give you an integer T, output T in English, and note that all of words are lower case. (0<=T<=9999)

Output

One answer One line.
Details see sample.

Sample Input

2034
1234
123
24
0

Sample Output

two thousand and thirty-four
one thousand and two hundred and thirty-four
one hundred and twenty-three
twenty-four
zero

答案

英语题~
注意数字的英语读法就行了

#include <iostream>
using namespace std;

const char *english[21] = {
	"zero","one","two","three","four","five","six","seven","eight","nine","ten",
	"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen",
	"eighteen","nineteen","twenty"
};

const char *english_[10] = {
	"zero","ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"
};

void print_english(int digit_1, int digit_2, int digit_3, int digit_4) {

	if (digit_4 != 0) {
		if (digit_1 == 0 && digit_2 == 0 && digit_3 == 0) {
			printf("%s thousand\n", english[digit_4]);
			return;
		}
		else
			printf("%s thousand and ", english[digit_4]);
	}
	if (digit_3 != 0) {
		if (digit_1 == 0 && digit_2 == 0) {
			printf("%s hundred\n", english[digit_3]);
			return;
		}
		else
			printf("%s hundred and ", english[digit_3]);
	}
	int val = digit_2 * 10 + digit_1;
	if (val % 10 == 0)
		printf("%s\n", english_[digit_2]);
	else if (val > 20)
		printf("%s-%s\n", english_[digit_2], english[digit_1]);
	else
		printf("%s\n", english[val]);
}

int main()
{
	int T;
	while (cin >> T) {
		int digit_4, digit_3, digit_2, digit_1;

		digit_1 = T % 10;
		T /= 10;
		digit_2 = T % 10;
		T /= 10;
		digit_3 = T % 10;
		T /= 10;
		digit_4 = T % 10;

		print_english(digit_1, digit_2, digit_3, digit_4);
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值