杭电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);
}
}