|
|
原帖由 cj402444206 于 2010-7-9 16:03 发表 ![]()
http://oraqa.com/2008/03/27/how- ... ombo-puzzle-in-sql/
How to solve the Stamp Combo Puzzle in SQL
邮票谜题:
父亲需要些1分,2分,3分,5分,10分的邮票,其中两种各买四张,另外的三种各买三张。我忘记是哪几种了。他给了我一些10分硬币,金额刚好买这些邮票。
March 27th, 2008 By Frank Zhou
The following is an interesting puzzle posted by Usenet rec-puzzles.org archive:
“Dad wants one-cent, two-cent, three-cent, five-cent, and ten-cent stamps.
He said to get four each of two sorts and three each of the others,
but I’ve forgotten which. He gave me exactly enough to buy them; just these dimes.”
How many stamps of each type does Dad want? A dime is worth ten cents.
------------------------------10G SQL Solution-----------------------------
SELECT '1*'||C1.CNT
||'+2*'||C2.CNT
||'+3*'||C3.CNT
||'+5*'||C4.CNT
||'+10*'||C5.CNT AS RESULT
FROM (SELECT LEVEL CNT FROM DUAL WHERE LEVEL BETWEEN 3 AND 4 CONNECT BY LEVEL
你这个写法和我后来在#33补充的第二个一样,是最简单的。 |
|