1963020
one million nine hundred and sixty three thousand and twenty
这种情况,到底是and twenty 还是 twenty,测试用例没有覆盖
1538088
one million five hundred and thirty eight thousand eighty eight
这是测试用例覆盖到大于 20 但百位为0的情况,是没有and的
#include <bits/stdc++.h>
using namespace std;
string s[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
"eleven", "twelve", "thirten", "fourten", "fifteen", "sixten", "seventen", "eighten", "nineten",
"twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety",
"hundred", "thousand", "million", "billion"};
string process(long &n) {
string t;
long x = n % 100;
n /= 100;
if (x <= 20) t = (n ? "and " : "") + s[x]; // (n % 10 ? "and " : "") + s[x]; 小于20百位为0没有and
else {
t = (n % 10 ? "and " : "") + s[x / 10 + 18] + (x % 10 == 0 ? "" : " " + s[x % 10]);
}
if (n && n % 10 != 0) t = s[n % 10] + " " + "hundred " + t;
n /= 10;
return move(t);
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
long n;
while (cin >> n) {
string t = process(n);
int i = 29;
while (n) {
t = process(n) + " " + s[i++] + " " + t;
}
cout << t << endl;
}
return 0;
}


京公网安备 11010502036488号