1 def main():
 2     time = ["one", "two", "three", "four", "five", "six", "seven", "eight","nine", 
 3        "ten", "eleven", "twelve", "thirteen", "fourteen", "quarter", "sixteen",
 4        "seventeen", "eighteen", "nineteen", "twenty", "twenty one", 
 5        "twenty two", "twenty three", "twenty four", "twenty five", 
 6        "twenty six", "twenty seven", "twenty eight", "twenty nine", "half"]
 7 
 8     h = int(raw_input())
 9     m = int(raw_input())
10     
11     msg = ""
12 
13     if h > 12:
14         h = h - 12
15         
16     if m == 0:
17         msg = time[h-1] + " o' clock"
18     elif m <= 30:
19         if m == 1:
20             msg = time[m-1] + ' minute past ' + time[h-1]
21         elif m == 15 or m == 30:
22             msg = time[m-1] + ' past ' + time[h-1]
23         else:
24             msg = time[m-1] + ' minutes past ' + time[h-1]
25     else:
26         m = 60 - m
27         if m == 15:
28             msg = time[m-1] + ' to ' + time[h]
29         else:
30             msg = time[m-1] + ' minutes to ' + time[h]
31 
32     print msg
33 
34 
35 main()

 

Link:

  https://www.hackerrank.com/challenges/the-time-in-words

学习

  预定义

  关键

    精确的情况分类和判断

 

 posted on 2015-05-17 10:27  sangocare  阅读(263)  评论(0编辑  收藏  举报