原题链接:蓝桥杯基础练习VIP-报时助手
解题思路:
注意事项:
参考代码:
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 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复