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

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

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

            Courage is grace under pressure

            用我一輩子去追求

            導航

            <2006年9月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            1234567

            統計

            • 隨筆 - 17
            • 文章 - 1
            • 評論 - 2
            • 引用 - 0

            常用鏈接

            留言簿(43)

            隨筆檔案

            文章檔案

            相冊

            XML的Blog

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            三道簡單算法題

            第一題
            /*
            ?求兩個字符串的最大公共子串
            ?String s1 = "abcdefghigj";
            ?String s2 = "xyzabcdeigj";
            ?則輸出abcde
            */

            第二題
            /*
            輸出楊輝三角形
            1
            1 1
            1 2 1
            1 3 3 1
            1 4 6 4 1
            1 5 10 10 5 1
            */

            第三題
            /*
            String[] a = {"a","b","c","d","e","f","g","h","i","j","",""};
            String[] b = {"f","a","c","f","e","k","l","y","p","o"};

            如果b里面的數據在a里面沒有,則把沒有的數據放到""里面,超過的話,則報"已經滿了,無法插入"~~
            */

            解析:
            第一題:
            public class first
            {
            ? public String search(String s1,String s2)
            ? {
            ? String max = "";
            ? for(int i=0; i<s1.length(); i++)
            ? {
            ??? for(int j=i; j<s1.length(); j++)
            ??? {
            ????? String sub = s1.substring(i,j);
            ????? if((s2.indexOf(sub)!=-1)&&sub.length()>max.length())
            ????? {
            ??????? max = sub;
            ????? }
            ??? }
            ? }?
            ? return max;
            ? }
            ?
            ? public static void main(String[] args)
            ? {
            ??? String s1 = "abcdefghigj";
            ??? String s2 = "xyzabcdefigj";
            ??? String output = new first().search(s1,s2);
            ??? System.out.println(output);
            ? }
            }

            第二題:
            public class second
            {
            ? public static int[] general(int[] data)
            ? {
            ??? int[] fanhui = new int[data.length+1];?
            ??? fanhui[0] = data[0];
            ??? for(int i=1,j=1; j<data.length; i++,j++)
            ??? {
            ????? fanhui[i] = data[j-1] + data[j];
            ??? }?????????
            ??? fanhui[fanhui.length-1] = data[data.length-1];
            ??? for(int k=0; k<fanhui.length; k++)
            ??? {
            ????? System.out.print(fanhui[k] + "\t");
            ??? }
            ??? System.out.print("\n");
            ??? return fanhui;
            ? }
            ? public static void main(String[] args)
            ? {
            ??? int times = 5;
            ??? int[] chushizhi = {1};
            ??? System.out.println(chushizhi[0]);
            ??? for(int i=0; i<times; i++)
            ??? {
            ??? chushizhi = second.general(chushizhi);???
            ??? }
            ? }
            }

            第三題:

            import java.util.ArrayList ;

            public class Third
            {
            public static void main(String[] args)
            {
            ??? String[] a = {"a","b","c","d","e","f","g","h","i","j","k","",""};
            ??? String[] b ={"f","a","c","f","e","k","l"};
            ??? Third third = new Third();
            ??? third.compareAndReplace(a,b);
            ??? StringBuffer output = new StringBuffer();
            ??? for(int i=0; i<a.length; i++)
            ??? output.append(a[i]);?
            ??? System.out.println("a已變成" + output.toString());
            ? }
            ?public void compareAndReplace(String[] a,String[] b)
            ?{
            ?? for(int i=0; i<b.length; i++)
            ?? {
            ????? outer:
            ???? for(int j=0; j<a.length; j++)
            ???? {
            ?????? if(b[i].equals(a[j]))
            ?????? break outer;
            ?????? if(j==a.length-1)
            ?????? {
            ?????? if(findFirstSpace(a)!=-1)
            ?????? {
            ???????? a[findFirstSpace(a)] = b[i];
            ?????? }
            ?????? else
            ?????? {
            ???????? System.out.println("已經滿了,無法插入" + b[i]);
            ?????? }??????
            ???? }
            ?? }
            ?}
            ?}
            ?
            ?public int findFirstSpace(String[] arg)
            ?{
            ?? for(int m=0; m<arg.length; m++)
            ?? {
            ???? if(arg[m].equals(""))
            ???? return m;????
            ?? }
            ?? return -1;
            ?}
            }

            posted on 2006-09-08 10:40 xyh 閱讀(1602) 評論(0)  編輯  收藏


            只有注冊用戶登錄后才能發表評論。


            網站導航:
             
            設為首頁 加入收藏 與我聯系 您的瀏覽器:

            主站蜘蛛池模板: 四虎永久在线精品免费一区二区| 亚洲欧洲日产国产最新| 色窝窝亚洲AV网在线观看| 野花高清在线电影观看免费视频| 亚洲精品永久www忘忧草| 99久久免费看国产精品| 911精品国产亚洲日本美国韩国| 久久国产精品2020免费m3u8 | 无码国模国产在线观看免费| 亚洲日本乱码卡2卡3卡新区| 毛片A级毛片免费播放| 亚洲色少妇熟女11p| 国产黄色片在线免费观看| 免费夜色污私人影院网站| 亚洲国产专区一区| 国产一二三四区乱码免费| 亚洲AV无码一区二区二三区软件| 免费无码一区二区三区蜜桃| 亚洲情a成黄在线观看动漫尤物| 曰批视频免费40分钟试看天天| 亚洲精品国产精品国自产网站| 日韩精品无码人妻免费视频| 永久免费精品影视网站| 无码乱人伦一区二区亚洲| 扒开双腿猛进入爽爽免费视频 | 黑人粗长大战亚洲女2021国产精品成人免费视频 | 2022免费国产精品福利在线| 亚洲国产精品成人精品无码区| 亚洲免费观看在线视频| 亚洲乱码日产精品一二三| 一本色道久久综合亚洲精品高清| 国产在线精品免费aaa片| 亚洲一区二区三区无码国产| 四虎影在线永久免费四虎地址8848aa | 久久亚洲精品视频| 国产成人免费在线| 美美女高清毛片视频黄的一免费 | 国产精品无码亚洲一区二区三区| 激情97综合亚洲色婷婷五| 中国人xxxxx69免费视频| 亚洲AV无码专区国产乱码不卡|