The Time in Words

时间:2021-11-25 02:52:07
 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. angular &dollar;http 与form表单的select

    产品线 产品 版本 代码是联动关系 ng-model 绑定数据 设置默认值 ng-options 填充option ng-change 选项变化时的操作截图如下: html <!DOCTYPE ...

  2. crc循环冗余校验

    循环冗余校验(Cyclic Redundancy Check, CRC)是一种根据网络数据包或电脑文件等数据产生简短固定位数校验码的一种散列函数,主要用来检测或校验数据传输或者保存后可能出现的错误.它 ...

  3. 解决SublimeCodeIntel回车换行误打代码

    SublimeCodeIntel会自动匹配并联想词汇, 这在换行的时候非常麻烦, 每次点Enter 都会误打出代码, 解决办法分两步:第一步是在Perferences/setting User 中加入 ...

  4. IMS Global Learning Tools Interoperability™ Implementation Guide

    Final Version 1.1 Date Issued:            13 March 2012 Latest version:         http://www.imsglobal ...

  5. 在64位的linux上运行32位的程序

    1.症状 (1)执行bin文件时提示:No such file or directory (2)ldd bin文件  的输出为: not a dynamic executable (3)file bi ...

  6. BZOJ 1856 字符串(组合)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1856 题意:有n个1和m个0组成的串,使得任意前k个中1的个数不少于0的个数.有多少种这 ...

  7. 修复关于apache-xampp的问题:Port 443 in use by &OpenCurlyDoubleQuote;vmware-hostd&period;exe”&excl;

    内容提要:复关于apache-xampp的问题:Port 443 in use by “vmware-hostd.exe”!在电脑里装了VMware后,再要装xampp,十有八九就会出现这个问题: 复 ...

  8. 面试被问之-----sql优化中in与exists的区别

    曾经一次去面试,被问及in与exists的区别,记得当时是这么回答的:''in后面接子查询或者(xx,xx,xx,,,),exists后面需要一个true或者false的结果",当然这么说也 ...

  9. 读DataSnap源代码(五)

    function TDSHTTPWebDispatcher.DispatchRequest(Sender: TObject; Request: TWebRequest; Response: TWebR ...

  10. 解决nginx中fastcgi&lpar;php-fpm&rpar;60s超时的问题

    在配置中加上 location ~ .*\.(php|php5)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_read_timeout 700; fastcgi_ ...