PAT1005 Spell It Right

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String num = reader.readLine();
        char[] datas = num.toCharArray();
        String sum = "0";
        for (int i = 0; i < datas.length; i++) {
            BigInteger data = new BigInteger(String.valueOf(datas[i]));
            sum = new BigInteger(sum).add(data).toString();
        }
        char[] result = sum.toCharArray();
        for (int i = 0; i < result.length; i++) {
            int digit = Integer.parseInt(String.valueOf(result[i]));
            switch (digit) {
                case 0:
                    System.out.print("zero");
                    break;
                case 1:
                    System.out.print("one");
                    break;
                case 2:
                    System.out.print("two");
                    break;
                case 3:
                    System.out.print("three");
                    break;
                case 4:
                    System.out.print("four");
                    break;
                case 5:
                    System.out.print("five");
                    break;
                case 6:
                    System.out.print("six");
                    break;
                case 7:
                    System.out.print("seven");
                    break;
                case 8:
                    System.out.print("eight");
                    break;
                case 9:
                    System.out.print("nine");
                    break;
                default:
                    break;
            }
            if (i < result.length - 1) {
                System.out.print(" ");
            }
        }
    }
}

你可能感兴趣的:(algorithm,PAT1005)