2020校招美团点评笔试

Posted qq188380780

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2020校招美团点评笔试相关的知识,希望对你有一定的参考价值。

小团数字转换问题

题目描述

就是将阿拉伯数字转换为中文大写数字

输入

一维字符串数组,每项为阿拉伯数字,数字保留 2 位且最大值不超过一万亿,

输出

转换后的数组

样例输入

["200.00","201.15","1015","200001010200"]

样例输出

["贰佰元整","贰佰零壹元壹角伍分","壹仟零壹拾伍元整","贰仟亿零壹佰零壹万零贰佰元整"]

思路

模拟!另外题目我看傻了!!!

编码

import java.util.*;

public class Main 
    private static final String[] str = "元", "拾", "佰", "仟", "万", "亿";
    private static final String[] num = "零", "壹","贰","叁","肆","伍","陆","柒","捌","玖";
    private static Deque<String> stack = new LinkedList<>();
    private static boolean getPoint(String s) 
        if(s.charAt(s.length()-3) == '.' && s.charAt(s.length()-2) != '0' && s.charAt(s.length()-1) != '0')
            return true;
        return false;
    
    private static String getStr(int count) 
        if(count < 5)
            return str[count];
        if(count < 8) 
            return str[count-4];
        
        if(count == 8) return str[5];
        return str[count-8];
    
    private static String getNum(int count) 
        return num[count];
    
    private static String change(String s) 
        boolean point = getPoint(s);
        int p = s.charAt(s.length()-3) == '.' ? s.length()-3 : s.length();
        if(point) 
            int fen = s.charAt(s.length()-1)-'0', jiao = s.charAt(s.length()-2)-'0';
            if(fen > 0) 
                stack.push(getNum(fen) + "分");
            
            if(jiao > 0) 
                stack.push(getNum(jiao) + "角");
            
         else 
            stack.push("整");
        
        boolean flag = false;
        for(int j = 0, i = p-1; i >= 0; --i, ++j) 
            int x = s.charAt(i)-'0';
            if(x != 0) 
                stack.push(getStr(j));
                stack.push(getNum(x));
                flag = true;
             else if(j == 0 || j == 4 || j == 8) 
                stack.push(getStr(j));
            else if(flag) 
                stack.push(getNum(x));
                flag = false;
            
        
        StringBuilder res = new StringBuilder();
        while(!stack.isEmpty()) 
            res.append(stack.pop());
        
        return res.toString();
    
    public static void main(String[] args) 
        Scanner scn = new Scanner(System.in);
        String input = scn.next(), head = "[\"", splitStr = "\",\"", tail = "\"]";
        input = input.substring(2, input.length()-2);
        String[] list = input.split(splitStr);
        for(int i = 0; i < list.length; ++i)
            list[i] = change(list[i]);
        System.out.print(head);
        System.out.print(list[0]);
        for(int i = 1; i < list.length; ++i) 
            System.out.print(splitStr);
            System.out.print(list[i]);
        
        System.out.println(tail);
    

以上是关于2020校招美团点评笔试的主要内容,如果未能解决你的问题,请参考以下文章

美团点评2020校招算法工程师方向笔试题

美团点评2017秋招笔试编程题

美团点评2017校招研发offer面经

美团点评2017秋招笔试编程题

名企笔试:美团点评2017秋招笔试真题(平衡二叉树)

记一次美团点评校招java面试经历