题解 | #学英语#

学英语

https://www.nowcoder.com/practice/1364723563ab43c99f3d38b5abef83bc

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();

        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("1", "one");
        hashMap.put("2", "two");
        hashMap.put("3", "three");
        hashMap.put("4", "four");
        hashMap.put("5", "five");
        hashMap.put("6", "six");
        hashMap.put("7", "seven");
        hashMap.put("8", "eight");
        hashMap.put("9", "nine");

        HashMap<String, String> tenthMap = new HashMap<>();
//        tenthMap.put("1", "one");
        tenthMap.put("2", "twenty");
        tenthMap.put("3", "thirty");
        tenthMap.put("4", "forty");
        tenthMap.put("5", "fifty");
        tenthMap.put("6", "sixty");
        tenthMap.put("7", "seventy");
        tenthMap.put("8", "eighty");
        tenthMap.put("9", "ninety");

        HashMap<String, String> tenthsMap = new HashMap<>();
        tenthsMap.put("0", "ten");
        tenthsMap.put("1", "eleven");
        tenthsMap.put("2", "twelve");
        tenthsMap.put("3", "thirteen");
        tenthsMap.put("4", "fourteen");
        tenthsMap.put("5", "fifteen");
        tenthsMap.put("6", "sixteen");
        tenthsMap.put("7", "seventeen");
        tenthsMap.put("8", "eighteen");
        tenthsMap.put("9", "nineteen");

        while (str.length() % 3 != 0) {
            str = "0" + str;
        }
        StringBuilder stringBuilder = new StringBuilder();
        int length = str.length();
        List<StringBuilder> list = new ArrayList<>();
        for (int i = length; i >= 0; i--) {
            boolean flag = false;
            String subString = str.substring(i - 3, i);
            int localResult = Integer.parseInt(subString);
            StringBuilder st = new StringBuilder();
            if (localResult != 0) {
                int digit = localResult % 10;
                localResult = localResult / 10;
                if (localResult != 0) {
                    int tenth = localResult % 10;
                    localResult = localResult / 10;
                    if (localResult != 0) {
                        int hundred = localResult % 10;
                        st.append(hashMap.get(String.valueOf(hundred))).append(" hundred ");
                        if (tenth != 0 || digit != 0) st.append("and ");
                    }
                    if (tenth >= 2) {
                        st.append(tenthMap.get(String.valueOf(tenth))).append(" ");
                        if (digit != 0) {
                            st.append(hashMap.get(String.valueOf(digit))).append(" ");
                            flag = true;
                        }
                    } else if (tenth == 1) {
//                        st.append("and ");
                        st.append(tenthsMap.get(String.valueOf(digit)));
                        flag = true;
                    } else if (digit != 0) {
                        st.append(hashMap.get(String.valueOf(digit))).append(" ");
                        flag = true;
                    }
                }
                if (!flag && digit != 0) st.append(hashMap.get(String.valueOf(digit))).append(" ");
            }
            list.add(st);
            i = i - 2;
            if (i - 1 <= 0) break;
        }
        String result = "";
        int listLength = list.size();
        result = list.get(0).toString();
        int i = 1;
        if (i < listLength) {
            result = list.get(i).toString() + "thousand " + result;
            i ++;
            if (i < listLength) {
                result = list.get(i).toString() + "million " + result;
                i ++;
                if (i < listLength) {
                    result = list.get(i).toString() + "billion " + result;
                }
            }
        }
        System.out.println(result);
    }
}

全部评论

相关推荐

佛系的本杰明反对画饼:个人看法,实习经历那段是败笔,可以删掉,它和你目标岗位没什么关系,没有用到什么专业技能,甚至会降低你项目经历内容的可信度。个人技能那里可以再多写一点,去boss直聘上看别人写的岗位要求,可以把你会的整合一下,比如熟悉常规的开关电源拓扑结构(BUCK、正激、反激、LLC等),熟悉常用的通信总线协议和通信接口,如UART,IIC,SPI等。简历首先是HR看的,HR大多不懂技术,会从简历里去找关键字,你没有那些关键字他可能就把你筛掉了,所以个人技能尽量针对着岗位描述写一下。还有电赛获佳绩,获奖了就写什么奖,没获奖就把获佳绩删了吧,要不会让人感觉夸大。
点赞 评论 收藏
分享
落叶随风呀:学校不好就放两栏,专业能力往前移, 政治面貌不是党员不如不写,籍贯湖南衡阳,或者湖南,浅尝辄止 基本信息排版不够美观,没有对齐 简历上花里胡哨的东西去掉 项目我不评价,因为我能力有限,且对mcu了解不足 但是这份简历掌握的水平,你可以海投试试,工作没问题但是工资应该不会高,因为搞mcu的小公司多
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务