2018/12/05 PAT刷题 L1-018 大笨钟 Java

花了很大的力气把题目从Scanner的输入方式改成BufferedReader和InputStreamReader的方式, 想法其实是很简单的, 就是执行的过程中, 不仔细, 导致有1个测试点一直过不去, 原来是输出语句有问题, 晕死了, 简单的题目就是考研耐性:

 1 import java.io.BufferedReader;
 2 import java.io.InputStreamReader;
 3 
 4 public class Main {
 5 
 6     public static void main(String[] args) throws Exception {
 7         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 8         String string = br.readLine();
 9         String[] str = string.split(":");
10         int hh = Integer.parseInt(str[0]);
11         int mm = Integer.parseInt(str[1]);
12         if (hh >= 0 && hh <= 11) {
13             // 在[1,12)这个区间, 输出语句
14             System.out.print("Only " + string + "." + "  Too early to Dang.");
15         }
16 
17         if (hh == 12) {
18             if (mm == 0) {
19                 // 如果是上午12点整点, 输出语句.
20                 System.out.print("Only " + string + "." + "  Too early to Dang.");  
21             } else {
22                 // 如果是12点非整点时间, 当作13点整点的情况输出语句
23                 System.out.print("Dang");
24             }
25         }
26         
27         if (hh >= 13 && hh <= 23) {
28             // 在下午1点到下午11点之间的情况.
29             if (mm == 0) {
30                 String[] st = new String[hh - 12];
31                 for (int i = 0; i < hh - 12; i++) {
32                     st[i] = "Dang";  // 输出hh-12个 "Dang"
33                 }
34                 for (int i = 0; i < hh - 12; i++) {
35                     System.out.print(st[i]);  // 输出hh-12个 "Dang"
36                 }
37             } else {
38                 // 在下午1点到下午11点的非整点的情况.
39                 String[] st = new String[hh + 1 - 12];
40                 for (int i = 0; i < hh + 1 - 12; i++) {
41                     st[i] = "Dang";  // 输出hh-12+1个 "Dang"
42                 }
43                 for (int i = 0; i < hh + 1 - 12; i++) {
44                     System.out.print(st[i]);  // 输出hh-12+1个 "Dang"
45                 }
46             }
47         }
48 
49     }
50 
51 }

猜你喜欢

转载自www.cnblogs.com/huangZ-H/p/10069760.html