• Java实现 蓝桥杯 蓝桥杯VIP 基础练习 数的读法


    问题描述

    当输入12 3456 7009时,会给出相应的念法:
      十二亿三千四百五十六万七千零九
      用汉语拼音表示为
      shi er yi san qian si bai wu shi liu wan qi qian ling jiu
      
      设计这样一个系统:给定一个阿拉伯数字串,你帮他按照中文读写的规范转为汉语拼音字串,相邻的两个音节用一个空格符格开。
      注意必须严格按照规范,比如说“10010”读作“yi wan ling yi shi”而不是“yi wan ling shi”,“100000”读作“shi wan”而不是“yi shi wan”,“2000”读作“er qian”而不是“liang qian”。

    样例输入

    1234567009

    样例输出

    shi er yi san qian si bai wu shi liu wan qi qian ling jiu

    这道题自我感觉就是一个时间的问题,不是很难,但可能很费时间
    package 蓝桥杯VIP;
    
    import java.util.Arrays;
    import java.util.Scanner;
    
    public class 数的读法 {
    	  public static void main(String[] args){
    	        Scanner scanner = new Scanner(System.in);
    	        readToChinese(scanner.nextInt());
    	    }
    
    
    public static void readToChinese(int n){
            if(n < 10000){
                thousandSay(n);
                System.out.println();
            }else if(n < 100000000){
                int n1 = n / 10000;
                int n2 = n % 10000;
                if(n2 == 0){
                    thousandSay(n1);
                    System.out.print("wan");
                    System.out.println();
                }else {
                    thousandSay(n1);
                    System.out.print("wan ");
                    thousandSay(n2);
                    System.out.println();
                }
            }else if(n < 2000000000){
                int n1 = n / 100000000;
                int n2 = (n/10000) % 10000;
                int n3 = n % 10000;
                thousandSay(n1);
                System.out.print("yi ");
                thousandSay(n2);
                System.out.print("wan ");
                thousandSay(n3);
                System.out.println();
            }else if(n == 2000000000){
                System.out.println("er yi");
                System.out.println();
            }else {
                System.out.println("输入错误,正确范围是(0-20 0000 0000)");
            }
        }
    public static void thousandSay(int n){
        String[] arr = new String[]{"ling ","yi ","er ","san ","si ","wu ","liu ","qi ","ba ","jiu "};
        String shi = "shi ";
        String bai = "bai ";
        String qian = "qian ";
        int num = n;
        if(n < 10){
            System.out.print(arr[n]);
        }else if(n < 100){
            int a = n / 10;
            int b = n % 10;
            if(b == 0){
                System.out.print(arr[a]+shi);
            }else if(a == 1){
                System.out.print(shi+arr[b]);
            } else {
                System.out.print(arr[a]+shi+arr[b]);
            }
        }
        else if(n < 1000){
            int a = n / 100;
            int b = (n / 10) % 10;
            int c = n % 10;
            if(b == 0 && c == 0){
                System.out.print(arr[a]+bai);
            }else if(b == 0 & c != 0){
                System.out.print(arr[a]+bai+arr[0]+arr[c]);
            }else if(b != 0 && c == 0){
                System.out.print(arr[a]+bai+arr[b]+shi);
            }else {
                System.out.print(arr[a]+bai+arr[b]+shi+arr[c]);
            }
        }else if(n < 10000){
            int a = n / 1000; //表示千位
            int b = (n / 100) % 10; //表示百位
            int c = (n / 10) % 10; //表示十位
            int d = n % 10; //表示个位
            if(b == c && c == d && d == 0){
                System.out.print(arr[a]+qian);
            }else if (b == 0 && c != 0 & d != 0){
                System.out.print(arr[a]+qian+arr[0]+arr[c]+shi+arr[d]);
            }else if(b == 0 && c == 0 && d != 0){
                System.out.print(arr[a]+qian+arr[0]+arr[d]);
            }else if (b == 0 && c != 0 && d == 0){
                System.out.print(arr[a]+qian+arr[0]+arr[c]+shi);
            }else if(c == 0 && d == 0){
                System.out.print(arr[a]+qian+arr[b]+bai);
            }else if (c == 0 && d != 0){
                System.out.print(arr[a]+qian+arr[b]+bai+arr[0]+arr[d]);
            }else if(d == 0){
                System.out.print(arr[a]+qian+arr[b]+bai+arr[c]+shi);
            }else {
                System.out.print(arr[a]+qian+arr[b]+bai+arr[c]+shi+arr[d]);
            }
        }
    }
    }
    
    
  • 相关阅读:
    12套有用的免费 PSD 格式 Android UI 素材
    使用 Canvas 和 JavaScript 创建逼真的下雨效果
    在网页设计中使用漂亮字体的16个优秀例子
    Koala – 开源的前端预处理器语言图形编译工具
    BackgroundCheck – 根据图片亮度智能切换元素样式
    经典网页设计:18个示例展示图片在网页中的使用
    TogetherJS – 酷!在网站中添加在线实时协作功能
    30个令人惊叹的灵感来自自然风光的网站设计《下篇》
    太有才了!创新的街头涂鸦手绘欣赏【中篇】
    15款美丽的设备模板,帮助展示你的 APP
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13079319.html
Copyright © 2020-2023  润新知