<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)系 ::  :: 管理 ::
      397 隨筆 :: 33 文章 :: 29 評(píng)論 :: 0 Trackbacks
    PLSQL算24點(diǎn)
    ?
    ?
    ??? 很早以前就想用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);
    ?
    posted on 2008-12-28 23:55 decode360 閱讀(155) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): 06.PLSQL
    主站蜘蛛池模板: 亚洲男女内射在线播放| 亚洲成A∨人片在线观看不卡| 猫咪www免费人成网站| 久久久久亚洲爆乳少妇无| 免费人成在线观看网站品爱网| 亚洲一区二区三区91| 亚洲真人日本在线| 91视频国产免费| 99久久精品毛片免费播放| 国产成人精品亚洲2020| 亚洲中文字幕无码永久在线| 美女视频黄是免费的网址| 一个人看的www免费高清| 亚洲一区欧洲一区| 亚洲成av人在线视| 免费少妇a级毛片| 无码国产精品一区二区免费式影视 | 在线jlzzjlzz免费播放| 天黑黑影院在线观看视频高清免费| 亚洲乱码卡一卡二卡三| 亚洲精品午夜无码电影网| 国产精品国产免费无码专区不卡| 久久免费的精品国产V∧| 一级人做人a爰免费视频| ww亚洲ww在线观看国产| 亚洲AV无码不卡在线播放| 免费大片黄手机在线观看| 成人A级毛片免费观看AV网站| 日韩免费电影网站| 一级毛片正片免费视频手机看| 亚洲中文字幕无码一去台湾| 亚洲国产成人久久精品动漫 | 欧美在线看片A免费观看| 一区二区三区无码视频免费福利 | 国产成人+综合亚洲+天堂| 亚洲黄色网站视频| 国精无码欧精品亚洲一区| 亚洲av午夜精品一区二区三区| 在线观看av永久免费| 最近中文字幕免费完整| 国产麻豆成人传媒免费观看|