<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Decode360's Blog

    業(yè)精于勤而荒于嬉 QQ:150355677 MSN:decode360@hotmail.com

      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 ::  :: 管理 ::
      302 隨筆 :: 26 文章 :: 82 評(píng)論 :: 0 Trackbacks

    ??? 很早以前就想用PLSQL寫(xiě)一個(gè)算24點(diǎn)的程序了,后來(lái)想了一下沒(méi)有研究下去,最近上ITPUB的時(shí)候正好大家都在討論,在大牛的基礎(chǔ)上修改了一下,基本上思想和算法都是沒(méi)有變的,就是學(xué)習(xí)了一下。還有兩個(gè)大問(wèn)題沒(méi)有處理好,一是只用了枚舉法,用PLSQL應(yīng)該可以換個(gè)更好的遞歸算法的;二是沒(méi)有濾重;反正最后的結(jié)果只是最簡(jiǎn)單的得到答案而已。

    ?

    ??? 具體的可以參見(jiàn):

    ??? http://www.itpub.net/viewthread.php?tid=1061129&extra=page%3D1%26amp%3Bfilter%3Ddigest&page=1

    ??? http://www.itpub.net/viewthread.php?tid=1077244&extra=&page=1

    ?

    ?

    ?

    create or replace function f_op (p_n1 number , p_op varchar2 , p_n2 number ) return number

    as

    begin

    ?? return case when p_op = '+' then p_n1 + p_n2

    ?????????????? when p_op = '-' then p_n1 - p_n2

    ?????????????? when p_op = '*' then p_n1 * p_n2

    ?????????????? when p_op = '/' and p_n2<> 0 then p_n1 / p_n2

    ?????????????? else null

    ????????? end ;

    end f_op;

    /

    ?

    ?

    ?

    create or replace procedure pro_24(p1 number , p2 number , p3 number , p4 number ) as

    ?

    r_result number default 0 ;

    ?

    begin

    ?

    ? for r in (

    ????? with t_num as

    ????????? ( select 1 id ,p1 as n from dual

    ?????????? union

    ?????????? select 2 id ,p2 as n from dual

    ?????????? union

    ?????????? select 3 id ,p3 as n from dual

    ?????????? union

    ?????????? select 4 id ,p4 as n from dual),

    ?????????? t_op as

    ????????? ( select '+' as o from dual

    ?????????? union

    ?????????? select '-' as o from dual

    ?????????? union

    ?????????? select '*' as o from dual

    ?????????? union

    ?????????? select '/' as o from dual)

    ?????? select distinct

    ????????????? a.n? as a,

    ????????????? o1.o as o1,

    ????????????? b.n? as b,

    ????????????? o2.o as o2,

    ????????????? c.n? as c,

    ????????????? o3.o as o3,

    ????????????? d.n? as d

    ???????? from t_num a, t_num b, t_num c, t_num d,

    ????????????? t_op? o1, t_op? o2, t_op? o3

    ??????? where a.id not in (b.id, c.id, d.id)

    ????????? and b.id not in (c.id, d.id)

    ????????? and c.id <> d.id) loop

    ?

    ?????? r_result := f_op(f_op(f_op(r.a,r.o1,r.b),r.o2,r.c),r.o3,r.d);

    ?????? if r_result between 23.9 and 24.1 then

    ?????? dbms_output.put_line( '((' ||r.a||r.o1||r.b|| ')' ||r.o2||r.c|| ')' ||r.o3||r.d);

    ?????? end if ; --((a b) c) d

    ??????

    ?????? r_result := f_op(f_op(r.a,r.o1,f_op(r.b,r.o2,r.c)),r.o3,r.d);

    ?????? if r_result between 23.9 and 24.1 then

    ?????? dbms_output.put_line( '(' ||r.a||r.o1|| '(' ||r.b||r.o2||r.c|| '))' ||r.o3||r.d);

    ?????? end if ; --(a (b c)) d

    ??????

    ?????? r_result := f_op(f_op(r.a,r.o1,r.b),r.o2,f_op(r.c,r.o3,r.d));

    ?????? if r_result between 23.9 and 24.1 then

    ?????? dbms_output.put_line( '(' ||r.a||r.o1||r.b|| ')' ||r.o2|| '(' ||r.c||r.o3||r.d|| ')' );

    ?????? end if ; --(a b) (c d)

    ??????

    ?????? r_result := f_op(r.a,r.o1,f_op(f_op(r.b,r.o2,r.c),r.o3,r.d));

    ?????? if r_result between 23.9 and 24.1 then

    ?????? dbms_output.put_line(r.a||r.o1|| '((' ||r.b||r.o2||r.c|| ')' ||r.o3||r.d|| ')' );

    ?????? end if ; --a ((b c) d)

    ???????????

    ?????? r_result := f_op(r.a,r.o1,f_op(r.b,r.o2,f_op(r.c,r.o3,r.d)));

    ?????? if r_result between 23.9 and 24.1 then

    ?????? dbms_output.put_line(r.a||r.o1|| '(' ||r.b||r.o2|| '(' ||r.c||r.o3||r.d|| '))' );

    ?????? end if ; --a (b (c d))

    ??????????

    ? end loop ;

    ?

    end ;

    ?

    /

    ?

    ?

    exec pro_24( 3 , 3 , 8 , 8 );





    -The End-

    posted on 2008-12-28 23:55 decode360-3 閱讀(235) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): SQL Dev
    主站蜘蛛池模板: 亚洲成AV人片在线观看ww| 亚洲中文字幕人成乱码| xxxx日本免费| 日本视频免费观看| 亚洲黄页网在线观看| 亚洲国产精品一区第二页| 亚洲黄色网址在线观看| 在线精品亚洲一区二区小说| 毛片a级毛片免费观看免下载| 免费国产成人午夜在线观看| 深夜a级毛片免费视频| 三级黄色免费观看| 日韩大片在线永久免费观看网站 | 亚洲熟妇久久精品| 91亚洲精品麻豆| 亚洲精品国产福利片| 亚洲av色福利天堂| 久久精品国产亚洲香蕉| 国产AV无码专区亚洲AVJULIA | 婷婷久久久亚洲欧洲日产国码AV| 亚洲免费闲人蜜桃| 特黄特色大片免费| jzzijzzij在线观看亚洲熟妇| 亚洲中字慕日产2021| 免费视频精品一区二区| 无码av免费网站| 今天免费中文字幕视频| 成年私人影院免费视频网站| 久久精品国产亚洲一区二区三区| 亚洲成av人片天堂网老年人| 国产午夜影视大全免费观看| 女人18毛片特级一级免费视频| 成人黄软件网18免费下载成人黄18免费视频 | 精品一卡2卡三卡4卡免费视频| 成年美女黄网站色大免费视频| 亚洲精品乱码久久久久久| 亚洲V无码一区二区三区四区观看| 亚洲18在线天美| 三级黄色片免费看| 国产v片免费播放| 亚洲欧洲精品国产区|