首页 > 专题系列 > Java解POJ > POJ 2840 Big Clock [解题报告] Java
2013
11-12

POJ 2840 Big Clock [解题报告] Java

Big Clock

问题描述 :

Our vicar raised money to have the church clock repaired for several weeks. The big clock, which used to strike the hours days and nights, was damaged several weeks ago and had been silent since then.

After the clock was repaired, it works all right, but there is still something wrong with it: the clock will strike thirteen times at one o’clock, fourteen times at two o’clock… 24 times at 12:00, 1 time at 13:00…

How many times will it strike now?

输入:

The first line consists of only one integer T (T <= 30), representing the number of test cases. Then T cases follow.

Each test case consists of only one line, representing the time now. Each line includes 2 integers H, M separated by a symbol “:”. (0 <= H < 24, 0 <= M < 60)

输出:

For each test case, output the answer in one line.

样例输入:

3
1:00
01:01
00:00

样例输出:

13
0
12

解题代码:

import java.util.*;  
   
 public class Main {  
     public static void main(String[] args) {  
         Scanner cin = new Scanner(System.in);  
           
         int num = Integer.valueOf(cin.nextLine()).intValue();  
         for(int i = 0; i < num; i++)  
         {  
             String[] str = cin.nextLine().split(":");  
             int hour = Integer.valueOf(str[0]).intValue();  
             int minute = Integer.valueOf(str[1]).intValue();  
               
             if(minute != 0)  
                 System.out.println("0");  
             else  
             {  
                 if(hour >= 0 && hour <= 12)  
                     System.out.println(hour+12);  
                 else  
                     System.out.println(hour-12);  
             }  
         }  
     }  
   }

  1. Good task for the group. Hold it up for every yeara??s winner. This is a excellent oppotunity for a lot more enhancement. Indeed, obtaining far better and much better is constantly the crucial. Just like my pal suggests on the truth about ab muscles, he just keeps obtaining much better.

  2. 算法是程序的灵魂,算法分简单和复杂,如果不搞大数据类,程序员了解一下简单点的算法也是可以的,但是会算法的一定要会编程才行,程序员不一定要会算法,利于自己项目需要的可以简单了解。

  3. 第一题是不是可以这样想,生了n孩子的家庭等价于n个家庭各生了一个1个孩子,这样最后男女的比例还是1:1

  4. 可以根据二叉排序树的定义进行严格的排序树创建和后序遍历操作。如果形成的排序树相同,其树的前、中、后序遍历是相同的,但在此处不能使用中序遍历,因为,中序遍历的结果就是排序的结果。经在九度测试,运行时间90ms,比楼主的要快。