题解 | #人民币转换#

人民币转换

https://www.nowcoder.com/practice/00ffd656b9604d1998e966d555005a4b

import java.util.*;
import java.io.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            String s = br.readLine();
            String[] split = s.split("\\.");
            Long num = Long.valueOf(split[0]);
            List<Long> list = new ArrayList();
            while (num != 0) {
                long yushu = num % 10000;
                list.add(yushu);
                num  = num / 10000;
            }
            List<String> subList = new ArrayList();
            subList.add("元");
            subList.add("拾");
            subList.add("佰");
            subList.add("仟");
            subList.add("万");
            subList.add("亿");
            subList.add("角");
            subList.add("分");
            subList.add("零");
            subList.add("整");
            Map<String, String> map = new HashMap();
            map.put("1", "壹");
            map.put("2", "贰");
            map.put("3", "叁");
            map.put("4", "肆");
            map.put("5", "伍");
            map.put("6", "陆");
            map.put("7", "柒");
            map.put("8", "捌");
            map.put("9", "玖");
            map.put("0", "零");
            StringBuffer stb = new StringBuffer();
            String temp = "";
            String cunfang = "";
            for (int i = 0; i < list.size(); i++) {
                int f = -1;
                int count = 0;
                long subNum = list.get(i);
                long beifen = list.get(i);
                if (subNum == 0) {
                    if (i == 0) {
                        temp = subList.get(0);
                    } else if (i == 1) {
                        temp = map.get("8") + temp;
                    }
                    continue;
                }
                if (i == 1 && count == 0) {
                    temp = subList.get(4) + temp;
                } else if (i == 2 && count == 0) {
                    temp = subList.get(5) + temp;
                }
                long a = 0;
                long b = 0;
                while (subNum != 0 || list.size() > i + 1 && count <= 3) {
                    count++;
                    a = subNum % 10;
                    f++;
                    if (a >= 1) {
                        if (a == 1 && count == 2) {
                            temp = subList.get(f) + temp;
                        } else {
                            if (i > 0 && count == 1) {
                                temp = map.get(String.valueOf(a)) + temp;
                            } else {
                                temp = map.get(String.valueOf(a)) + subList.get(f) + temp;
                            }
                        }
                    } else if (a == 0) {
                        if (count == 1) {
                            temp = subList.get(0);
                        } else if (a != b) {
                            temp = map.get(String.valueOf(a)) + temp;
                        }
                    }
                    b = subNum % 10;
                    subNum /= 10;
                }
            }
            if ("00".equals(split[1])) {
                temp = temp + subList.get(9);
            } else if (split[1].charAt(0) != '0' && split[1].charAt(1) != '0') {
                temp = temp + map.get(String.valueOf(split[1].charAt(0))) + subList.get(
                           6) + map.get(String.valueOf(split[1].charAt(1))) + subList.get(7);
            } else if (split[1].charAt(0) != '0') {
                temp = temp + map.get(String.valueOf(split[1].charAt(0))) + subList.get(6);
            } else {
                temp = temp + map.get(String.valueOf(split[1].charAt(1))) + subList.get(7);
            }
            System.out.println("人民币"+temp);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

全部评论

相关推荐

2025-12-31 19:23
已编辑
门头沟学院 Java
ssob是已读不回的,字节是压根不敢投的,简历是反反复复改了N遍的,八股是永远背不完的😅😅😅扯远了,道心破碎了,把简历发出来让大伙先看看笑话。再说正事。寒假日常实习还是很难找,连个面试都难约,我不是个例,这是网上普遍反映。不报希望了,趁着2、3月前赶紧做些什么才是。扔几个碎碎念:1.这破简历还能怎么改?写到什么程度才能过实习岗筛选?广大牛友来锐评一下2.火速辅修go,是否可行目前看来是学习成本最小的。首先,很多go实习岗位已经明确要求掌握gin等技术栈,拿java简历投go的时代已经过去了。其次,很多后端的东西,MySQL、Redis这些都是通用的,不用重新学。所以这个问题就具体为:2.1&nbsp;java&amp;go混血简历怎么写第一个项目,仿大麦的微服务,不太好改。因为有用到Redisson、AOP、SpringAI这些java强相关的东西,包装成go需要替换这些方案。第二个,点评魔改。应该可以包装成go,github上也有人用go重写过。2.2&nbsp;java&amp;go通用的轮子RPC直接pass了,太烂大街了。不知道动态线程池能不能做。反正项目上新有风险,不一定来得及,非必要就不开新的项目。补充:别跟我扯RAG了,这玩意已经成新的烂大街了,详见我上一篇的吐槽。3.认真学微调prompt什么的这个半步踩进算法了已经。八股和场景题完全就是另一套,没两三个月搞不定的。约等于换方向
简历中的项目经历要怎么写
点赞 评论 收藏
分享
ldyllic:飞神,985+美团+腾讯+京东,无敌飞飞神
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务