zoukankan      html  css  js  c++  java
  • 小写数字转化为大写数字(小米OJ题与蓝桥杯题)

    import java.util.*;
    public class Main {
        public static void main(String args[]) {
            Scanner scan = new Scanner(System.in);
            String str;
            String[] num = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
            while (scan.hasNextLine()) {
                str = scan.nextLine().trim();
                if (str.equals("0")) {
                    System.out.println("零元整");
                    continue;
                }
                int len = str.length();
                String ans = "";
                for (int i = 0; i < len; i++) {
                    int x = str.charAt(i) - '0';
                    if ((len - i) % 4 == 0) {
                        if (x != 0) ans += num[x] + "仟";
                        else if (str.charAt(i + 1) != '0') ans += "零";
                    }
                    if ((len - i) % 4 == 1) {
                        if (x != 0) {
                            if ((len - i) == 1) ans += num[x];
                            else if ((len - i) == 5) ans += num[x] + "万";
                            else if ((len - i) == 9) ans += num[x] + "亿";
                        } else {
                            if ((len - i) == 5) ans += "万";
                            else if ((len - i) == 9) ans += "亿";
                        }
                    }
                    if ((len - i) % 4 == 2) {
                        if (x != 0) ans += num[x] + "拾";
                        else if (str.charAt(i + 1) != '0') ans += "零";
                    }
                    if ((len - i) % 4 == 3) {
                        if (x != 0) ans += num[x] + "佰";
                        else if (str.charAt(i + 1) != '0') ans += "零";
                    }
                }
                
                ans = ans.replace("亿万","亿");
                ans+="元整";
                System.out.println(ans);
            }
        }
    }
        
    

      

    不忘初心,方得始终。只有走过弯路,才更确信当初最想要的是什么。
  • 相关阅读:
    linux下创建一个指定大小的文件
    批量替换多个文件中的字符串
    redhat 搭建yum 源
    python ConfigParser 模块
    python yaml 模块
    python xml文件处理
    py2exe 和pyinstaller打包
    wxpython 学习之 --threading
    wxpython 学习之 --文本框与Boxsizer布局管理器
    wxpython 学习之 --窗口分割
  • 原文地址:https://www.cnblogs.com/wszhu/p/12875372.html
Copyright © 2011-2022 走看看