思路:
题意好理解,就是数字长度不限定,不过Java里面有BigInteger,试一下里面的几个函数这题也就好处理了。
import java.util.Scanner;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// BigInteger num = new BigInteger(input.next());
// int sum = 0;
// while(num.intValue()!=0) {
// sum += num.mod(new BigInteger("10")).intValue();
// num = num.divide(new BigInteger("10"));
// }
String str = input.next();
int sum = 0;
for(int i=0; i<str.length(); i++)
sum += str.charAt(i)-'0';
String alpha[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
String s = sum+"";
for(int i=0; i<s.length(); i++) {
if(i==0)
System.out.print(alpha[Integer.parseInt(s.charAt(i)+"")]);
else
System.out.print(" " + alpha[Integer.parseInt(s.charAt(i)+"")]);
}
input.close();
}
}