posts - 73,  comments - 55,  trackbacks - 0
          /*
          ?求兩個字符串的最大公共子串
          ?String?s1?=?"abcdefghigj";
          ?String?s2?=?"xyzabcdeigj";
          ?則輸出abcde
          */
          ?
          public ? class ?Test
          {
          ??
          public ?String?search(String?s1,String?s2)
          ??
          {
          ??String?max?
          = ? "" ;
          ??
          for ( int ?i? = ? 0 ;?i? < ?s1.length();?i ++ )
          ??
          {
          ????
          for ( int ?j? = ?i + 1 ;?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?
          = ? " abedafghigj " ;
          ????String?s2?
          = ? " xyzabfddfigj " ;
          ????String?output?
          = ? new ?Test().search(s1,s2);
          ????System.out.println(output);
          ??}

          }
          posted on 2007-03-05 15:50 保爾任 閱讀(909) 評論(0)  編輯  收藏 所屬分類: Arithmetic & Data Structure

          <2007年3月>
          25262728123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 田林县| 临沭县| 衡阳县| 高州市| 常州市| 腾冲县| 昌宁县| 嘉黎县| 沁水县| 文安县| 新绛县| 融水| 江安县| 小金县| 安化县| 青岛市| 长沙市| 安国市| 习水县| 玉环县| 汶川县| 辽阳市| 汤阴县| 崇礼县| 英山县| 普洱| 文成县| 锦屏县| 抚宁县| 婺源县| 汉寿县| 普安县| 玛多县| 德令哈市| 丰台区| 建德市| 铁力市| 万荣县| 敖汉旗| 微博| 旬邑县|