[PTA] 1002. 写出这个数 (Basic)

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        Map<Integer, String> map = new HashMap<Integer, String>();
        map.put(1, "yi");
        map.put(2, "er");
        map.put(3, "san");
        map.put(4, "si");
        map.put(5, "wu");
        map.put(6, "liu");
        map.put(7, "qi");
        map.put(8, "ba");
        map.put(9, "jiu");
        map.put(0, "ling");

        int len = n.length();
        int temp = 0;
        for (int i = len - 1; i >= 0; --i) {
            temp += n.charAt(i) - '0';
        }

        int x;
        Stack<Integer> sta = new Stack<Integer>();

        while (temp != 0) {
            x = temp % 10;
            sta.push(x);
            temp /= 10;
        }
        int staLen = sta.size();

        for (int j = 0; j < staLen - 1; j++) {
            System.out.print(map.get(sta.pop()) + " ");
        }
        System.out.print(map.get(sta.pop()));
        sc.close();
    }
}

猜你喜欢

转载自www.cnblogs.com/ruoh3kou/p/9967003.html