题解 | #学英语#

学英语

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] nums = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "forteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
        String[] ties = {"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
        String[] units = {"", "thousand", "million", "billion"};
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLong()) { // 注意 while 处理多个 case
            String ans = "";
            int unit = 0;
            for (long n = in.nextLong(); n != 0; n /= 1000) {
                int m = (int) n % 1000, bit = m % 10, ten = m / 10 % 10, hundred = m / 100;
                String part = "";
                if (hundred > 0) {
                    part += nums[hundred] + " hundred ";
                    if (ten > 0 || bit > 0) {
                        part += "and ";
                    }
                }
                if (ten < 2) {
                    part += nums[m % 100] + " ";
                } else {
                    part += ties[ten] + " ";
                    if (bit > 0) {
                        part += nums[bit] + " ";
                    }
                }
                ans = part + units[unit++] + " " + ans;
            }
            System.out.println(ans);
        }
    }
}

全部评论

相关推荐

一个菜鸡罢了:哥们,感觉你的简历还是有点问题的,我提几点建议,看看能不能提供一点帮助 1. ”新余学院“别加粗,课程不清楚是否有必要写,感觉版面不如拿来写一下做过的事情,教育经历是你的弱势就尽量少写 2. “干部及社团经历”和“自我评价”删掉 3. 论文后面的“录用”和“小修”啥的都删掉,默认全录用,问了再说,反正小修毕业前肯定能发出来 4. 工作经验和研究成果没有体现你的个人贡献,着重包装一下个人贡献
点赞 评论 收藏
分享
走不到的路就这样算了吗:大佬硬气
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务