首页 > 其他 > 详细

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

时间:2018-11-16 00:57:59      阅读:234      评论:0      收藏:0      [点我收藏+]
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();
    }
}

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

原文:https://www.cnblogs.com/ruoh3kou/p/9967003.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!