想了个歪点子:把A按照2个汉字一个串取出来,如n1="今天"、n2="我要"....得到总串数 m设置n=0,循环对n1、n2......在B中搜索,如果B中也存在,则n+1最后n/m得到一个半分比,至于80%还是90%之上才算相似楼主自己定其实也不一定2个汉字一个串,3个、4个都可以,再常感觉就不好了希望抛砖引玉^_^

解决方案 »

  1.   

    http://www.dcs.shef.ac.uk/~sam/stringmetrics.html#hammingThis is a very good algorithm.
      

  2.   

    我想,将两个字符串分别调用 String 类的 public char[] toCharArray() 方法生成两个字符数组 (如 c1,c2)再用 for 循环比较相同下标的字符是否相同,再用一个 count 变量在两个字符相同时自动加 1 。如果 count 变量值大于字符串长度的一定比例,就算这两个字符串相似;如要count 与两个字符串的长度相等的话,就说明这两个字符串相等;如果 count 变量值小于字符串长度的一定比例,就算这两个字符串不相似也不相等!
        这只是我粗略的想法。就该可行。希望能帮上忙。   ^_^
      

  3.   

    算法道论上的
    In biological applications, we often want to compare the DNA of two (or more) different organisms. A strand of DNA consists of a string of molecules called bases, where the possible bases are adenine, guanine, cytosine, and thymine. Representing each of these bases by their initial letters, a strand of DNA can be expressed as a string over the finite set {A, C, G, T}. (See Appendix C for a definition of a string.) For example, the DNA of one organism may be S1= ACCGGTCGAGTGCGCGGAAGCCGGCCGAA, while the DNA of another organism may be S2 = GTCGTTCGGAATGCCGTTGCTCTGTAAA. One goal of comparing two strands of DNA is to determine how "similar" the two strands are, as some measure of how closely related the two organisms are. Similarity can be and is defined in many different ways. For example, we can say that two DNA strands are similar if one is a substring of the other. (Chapter 32 explores algorithms to solve this problem.) In our example, neither S1 nor S2 is a substring of the other. Alternatively, we could say that two strands are similar if the number of changes needed to turn one into the other is small. (Problem 15-3 looks at this notion.) Yet another way to measure the similarity of strands S1 and S2 is by finding a third strand S3 in which the bases in S3 appear in each of S1 and S2; these bases must appear in the same order, but not necessarily consecutively. The longer the strand S3 we can find, the more similar S1 and S2 are. In our example, the longest strand S3 is GTCGTCGGAAGCCGGCCGAA.
      

  4.   

    faen(发恩) 你那个算法有没有中文解析啊?看不懂呢!
      

  5.   

    什么叫相似呢?按照 faen(发恩)的资料,如果字串s1和s2中,有一个是另一个的子串,那么可以定义这两个很"相似",否则,如果找到一个第三方字符串s3且s3同时是s1和s2的子串,那么s1和s2也可以认为"相似".
      

  6.   

    可否比较两个String中字符相同的个数
    来比较?