def main():
time = ["one", "two", "three", "four", "five", "six", "seven", "eight","nine",
"ten", "eleven", "twelve", "thirteen", "fourteen", "quarter", "sixteen",
"seventeen", "eighteen", "nineteen", "twenty", "twenty one",
"twenty two", "twenty three", "twenty four", "twenty five",
"twenty six", "twenty seven", "twenty eight", "twenty nine", "half"] h = int(raw_input())
m = int(raw_input()) msg = "" if h > 12:
h = h - 12 if m == 0:
msg = time[h-1] + " o' clock"
elif m <= 30:
if m == 1:
msg = time[m-1] + ' minute past ' + time[h-1]
elif m == 15 or m == 30:
msg = time[m-1] + ' past ' + time[h-1]
else:
msg = time[m-1] + ' minutes past ' + time[h-1]
else:
m = 60 - m
if m == 15:
msg = time[m-1] + ' to ' + time[h]
else:
msg = time[m-1] + ' minutes to ' + time[h] print msg main()

Link:

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

学习

  预定义

  关键

    精确的情况分类和判断

随机推荐

  1. C语言初学 使用while语句统计输入字符个数

    #include<stdio.h> main() { int n=0; printf("输入任意个数的字符:\n"); while(getchar()!='\n')n+ ...

  2. linux内核学习之一:环境搭建--安装Debian7.3

    本系列文章假设读者已对linux有一定的了解,其实学习linux内核不需要有很深的关于linux的知识,只需要了解以下内容:linux基础知识及基本shell命令:现代操作系统的基本概念:C语言和gc ...

  3. cf Sereja and Array

    http://codeforces.com/contest/315/problem/B #include <cstdio> #include <cstring> #includ ...

  4. ActionBarActivity & FragmentActivity

    1 ActionBarActivity 是FragmentActivity的一个子类 2 ActionBarActivity 加入了对actionBar的操作, 比如getSupportActionB ...

  5. 【Android】通过Java代码替换TabHost中的drawableTop资源

    在博客 http://blog.csdn.net/jueblog/article/details/11837445 中的Tab选项卡中, 点击相应的Tab选项,图标没有发生改变. 这些资源图片也没有尽 ...

  6. 11G在线重建索引

    SQL> select count(*) from test_idx; COUNT(*) ---------- 19087751 SQL> select segment_name,segm ...

  7. HDU5044---Tree 树链剖分

    大致题意:add1 u v   u到v路径上所有点的权值加上k,add2  u 到v路径上所有边的权值加上k 最后输出所有点的权值,边的权值..树链剖分预处理然后来个线性O(n)的操作.刚开始用线段树 ...

  8. c语言else匹配问题

    #include <stdio.h> #include <stdlib.h> //实现 依次输入三个递增的数 然后正确输出 //为什么得不到我们想要的结果呢 这就是else匹配 ...

  9. c指针点滴-指针与类型

    #include <stdio.h> #include <stdlib.h> //数据通信 void main() { ; int *p1 = &num; int *p ...

  10. LeetCode 191. Number of 1 Bits Question

    题意:给你一个整数,计算该整数的二进制形式里有多少个“1”.比如6(110),就有2个“1”. 一开始我就把数字n不断右移,然后判定最右位是否为1,是就cnt++,否则就继续右移直到n为0. 可是题目 ...