ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Digital Watch

Digital Watch

原创 Linux操作系统 作者:yaubin 时间:2010-11-25 17:18:58 0 删除 编辑

Digital Watch

You have a digital watch showing the hour, the minute and the second in 24-hour notation. (example: 00:12:59, 23:45:00 etc.) At some time you look at your watch and observe that these six digits are all different. If you replace all the digits with the number of pieces used to show the corresponding numeral in the digital layout, then you get a new time, which also has the property of consisting of six different digits.

At what time, the difference between those two times are maximum?

Example: If the time was 01:23:45, then we get 62:55:45 from the number of pieces on the digital layout. But it is not a valid time in 24-hour notation.

The number of pieces for all digits in digital layout are as follows: (six for 0, two for 1, five for 2, five for 3, four for 4, five for 5, six for 6, three for 7, seven for 8, six for 9)

Enter your answer as six digits, without using spaces or colons. That is to say, enter 012345 for 01:23:45.

 

 

 

 

sql解答:

WITH
conf --转换规则表
AS (
SELECT 6 r,0 s FROM dual UNION
SELECT 2 r,1 s FROM dual UNION
SELECT 5 r,2 s FROM dual UNION
SELECT 5 r,3 s FROM dual UNION
SELECT 4 r,4 s FROM dual UNION
SELECT 5 r,5 s FROM dual UNION
SELECT 6 r,6 s FROM dual UNION
SELECT 3 r,7 s FROM dual UNION
SELECT 7 r,8 s FROM dual UNION
SELECT 6 r,9 s FROM dual
),
hh AS (SELECT ROWNUM-1 hh FROM dual CONNECT BY LEVEL<=24),--小时
mm AS (SELECT ROWNUM-1 mm FROM dual CONNECT BY LEVEL<=60),--分钟
sc AS (SELECT ROWNUM-1 sc FROM dual CONNECT BY LEVEL<=60),--秒钟
tm --从00:00:00 到23:59:59 的所有时间
AS (
SELECT CASE WHEN length(hh)=1 THEN '0'||hh ELSE to_char(hh) END||
       CASE WHEN length(mm)=1 THEN '0'||mm ELSE to_char(mm) END||
       CASE WHEN length(sc)=1 THEN '0'||sc ELSE to_char(sc) END tm
   FROM hh,mm,sc),
tc --从00:00:00 到23:59:59 的所有时间 和转换后的字符串
AS (SELECT tm,(SELECT r FROM conf WHERE s=SUBSTR(tm,1,1))||
                 (SELECT r FROM conf WHERE s=SUBSTR(tm,2,1))||
                 (SELECT r FROM conf WHERE s=SUBSTR(tm,3,1))||
                 (SELECT r FROM conf WHERE s=SUBSTR(tm,4,1))||
                 (SELECT r FROM conf WHERE s=SUBSTR(tm,5,1))||
                 (SELECT r FROM conf WHERE s=SUBSTR(tm,6,1)) cg FROM tm),
tr --转换后字符串为有效时间,并且将2个时间对应的日期值放到表里
AS (
SELECT tm,cg,to_date(tm,'hh24miss') dtm,to_date(cg,'hh24miss') dcg
FROM tc WHERE to_number(substr(cg,1,2))<=23 AND
                       to_number(substr(cg,3,2))<=59 AND
                       to_number(substr(cg,5,2))<=59)
SELECT * FROM (SELECT tm,cg,24*60*60*(dcg-dtm) vl
 FROM tr  ORDER BY 3 DESC) WHERE ROWNUM=1 --查询出日期差最大的那个;

结果:112020 225656,就是11:20:20 这个时间

 

 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/13438681/viewspace-680292/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 砝码问题
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2010-11-12

  • 博文量
    3
  • 访问量
    1652