1,先比较两个字符串大小,记录差值(n)。
2,搜索str2中 字符增1位(减1位)能与str1中相同的个数,补齐,从n中减去这个值。
3,搜索str2中 字符增2位(减2位)能与str1中相同的个数,补齐,从n中减去这个值。

4,n==0或搜索不到时,直接补齐。呵呵 偶是菜菜,随便想想

解决方案 »

  1.   

    楼主没有把问题说清楚吧
    用StringBuilder类
      

  2.   

    StringBuilder str1=new StringBuilder("sdfsdfs");
    StringBuilder str2=new StringBuilder();
    str2.Append(str1.ToString());
      

  3.   

    谢谢大家, 不好意思, 我题目没说清楚, 我弄的东西是:
    因为这是我对文本处理时碰到的问题, 要判断两个文本是否具有一定的相似性, 如果相似则两个文本只取一个。  而判断txt2是否与txt1文本相似, 得知道txt2 最少得经过多少次 插入 和 删除  才能与txt1一样。(一个英文单词当作一个汉字看待).谢谢大家!!
      

  4.   


    有个公式啦,diff = (remove + insert)/ length1 + length2, 其中remove and insert are the number of words to be removed and inserted in the second in order to obtain the first one.
    length1 and length2 are the length in wordds of the first and the second text, respectively.diff有个阈值,超过了就认为是不相似的了,
      

  5.   

    为什么老是有人问 LCS 算法呢上面的方法均错!自己 google LCS
      

  6.   

    LCS是什么哦?? 没听说过, up