def numberToWords(num):
if num == 0:
return "zero"
ones = ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen",
"seventeen", "eighteen", "nineteen"]
tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
def helper(n):
if n == 0:
return ""
elif n < 20:
return ones[n] + " "
elif n < 100:
return tens[n//10] + " " + ones[n%10] + " "
elif n < 1000:
if n % 100 == 0:
return ones[n//100] + " hundred "
return ones[n//100] + " hundred and " + helper(n%100)
elif n < 1000000:
if n % 1000 == 0:
return helper(n//1000) + "thousand "
return helper(n//1000) + "thousand " + helper(n%1000)
else:
if n % 1000000 == 0:
return helper(n//1000000) + "million "
return helper(n//1000000) + "million " + helper(n%1000000)
ans = helper(num).strip()
return ans.replace(" ", " ")
# 处理输入
n = int(input())
print(numberToWords(n))
import java.util.*;
public class Main {
private final String[] ONES = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
private final String[] TENS = {"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
public String numberToWords(int num) {
if (num == 0) return "zero";
return helper(num).trim();
}
private String helper(int num) {
StringBuilder result = new StringBuilder();
if (num >= 1000000) {
result.append(helper(num / 1000000)).append("million ");
num %= 1000000;
}
if (num >= 1000) {
result.append(helper(num / 1000)).append("thousand ");
num %= 1000;
}
if (num >= 100) {
result.append(ONES[num / 100]).append(" hundred ");
if (num % 100 != 0) {
result.append("and ");
}
num %= 100;
}
if (num >= 20) {
result.append(TENS[num / 10]).append(" ");
if (num % 10 != 0) {
result.append(ONES[num % 10]).append(" ");
}
} else if (num > 0) {
result.append(ONES[num]).append(" ");
}
return result.toString();
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println(new Main().numberToWords(n));
}
}
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Solution {
private:
vector<string> ones = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
vector<string> tens = {"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
string helper(int num) {
if (num == 0) return "";
string result;
if (num >= 1000000) {
result += helper(num / 1000000) + "million ";
num %= 1000000;
}
if (num >= 1000) {
result += helper(num / 1000) + "thousand ";
num %= 1000;
}
if (num >= 100) {
result += ones[num / 100] + " hundred ";
if (num % 100 != 0) {
result += "and ";
}
num %= 100;
}
if (num >= 20) {
result += tens[num / 10] + " ";
if (num % 10 != 0) {
result += ones[num % 10] + " ";
}
} else if (num > 0) {
result += ones[num] + " ";
}
return result;
}
public:
string numberToWords(int num) {
if (num == 0) return "zero";
string result = helper(num);
// 删除末尾空格
while (result.back() == ' ') {
result.pop_back();
}
return result;
}
};
int main() {
int n;
cin >> n;
Solution solution;
cout << solution.numberToWords(n) << endl;
return 0;
}