|
最后一题,比较简单:
#20 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.
你有一个数字手表,用24小时制显示时分秒。(例如:00:12:59, 23:45:00等)在某个时间点你发现六个数字各不相同。如果你把这些数字用它们的显示笔划数代替,那么你得到一个新的时间,而且六位仍然各不相同。
在什么时刻,这两个时间的差距最大?
例子:假如时间是01:23:45, 那么我们从各个数字的显示笔划数得到的新时间是 62:55:45。但这不是一个有效的时间。
所有数字的显示笔划数如下:(注:这是七段数码管的显示笔划数)
0: 6段
1: 2段
2: 5段
3: 5段
4: 4段
5: 5段
6: 6段
7: 3段
8: 7段
9: 6段
SELECT t,new_t
FROM ( SELECT tm.*
,RANK() OVER(ORDER BY ABS(TO_DATE('20100101'||t,'YYYYMMDDHH24MISS')-TO_DATE('20100101'||new_t,'YYYYMMDDHH24MISS')) DESC) rnk
FROM (SELECT *
FROM (SELECT h||m||s AS t
,TRANSLATE(h||m||s,'0123456789','6255456376') new_t
FROM (SELECT LPAD(ROWNUM-1,2,'0') AS h FROM DUAL CONNECT BY ROWNUM<=24)
,(SELECT LPAD(ROWNUM-1,2,'0') AS m FROM DUAL CONNECT BY ROWNUM<=60)
,(SELECT LPAD(ROWNUM-1,2,'0') AS s FROM DUAL CONNECT BY ROWNUM<=60)
)
WHERE SUBSTR(new_t,1,2) BETWEEN '00' AND '23'
AND SUBSTR(new_t,3,2) BETWEEN '00' AND '59'
AND SUBSTR(new_t,5,2) BETWEEN '00' AND '59'
AND LENGTH(TRANSLATE('0123456789','$'||t,'$'))=4
AND LENGTH(TRANSLATE('0123456789','$'||new_t,'$'))=4
) tm
)
WHERE rnk=1;
T NEW_T
------------------------ ----------
172048 235647 |
|