Mr.Clutch


私信TA

用户名:uq_63396757599

访问量:5239

签 名:

等  级
排  名 2459
经  验 2201
参赛次数 0
文章发表 20
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;

public class Main {
    static StreamTokenizer cin;
    static PrintWriter out;
    static int h; // 时
    static int m; // 分
    static HashMap<Integer, String> map;
    public static void main(String[] args) throws IOException{
        cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(new OutputStreamWriter(System.out));
        h = nextInt();
        m = nextInt();
        map = new HashMap<>();
        initMap();
        StringBuilder str = new StringBuilder();
        for(int item : splitH())
            str.append(map.get(item)).append(" ");
        if(m == 0)
            str.append("o'clock");
        else{
            for(int item : splitM()){
                str.append(map.get(item)).append(" ");
            }
        }
        out.println(str.toString());
        out.flush();
    }

    static ArrayList<Integer> splitH(){
        ArrayList<Integer> list = new ArrayList<>();
        if(h > 20){
            int s1 = h%10;  // 个位
            int s2 = h-s1;  // 十位
            list.add(s2);
            if(s1 != 0)
                list.add(s1);
        }else
            list.add(h);
        return list;
    }

    static ArrayList<Integer> splitM(){
        ArrayList<Integer> list = new ArrayList<>();
        if(m > 20){
            int s1 = m%10;  // 个位
            int s2 = m-s1;  // 十位
            list.add(s2);
            if(s1 != 0)
                list.add(s1);
        }else
            list.add(m);
        return list;
    }

    static void initMap(){
        map.put(0, "zero");
        map.put(1, "one");
        map.put(2, "two");
        map.put(3, "three");
        map.put(4, "four");
        map.put(5, "five");
        map.put(6, "six");
        map.put(7, "seven");
        map.put(8, "eight");
        map.put(9, "nine");
        map.put(10, "ten");
        map.put(11, "eleven");
        map.put(12, "twelve");
        map.put(13, "thirteen");
        map.put(14, "fourteen");
        map.put(15, "fifteen");
        map.put(16, "sixteen");
        map.put(17, "seventeen");
        map.put(18, "eighteen");
        map.put(19, "nineteen");
        map.put(20, "twenty");
        map.put(30, "thirty");
        map.put(40, "forty");
        map.put(50, "fifty");

    }

    static int nextInt() throws IOException{
        cin.nextToken();
        return (int) cin.nval;
    }
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区