@@ -0,0 +1,2189 @@
+package algorithm;%0A%0A/**%0A * Created by yefeng on 16/10/30.%0A */%0Apublic class LongComStr %7B%0A%0A    public static void getLCString(String str1, String str2) %7B%0A        char%5B%5D cStr1, cStr2;%0A        int len1, len2, minLen;%0A        int%5B%5D c, max, maxIndex;%0A%0A        if (str1.length() %3E str2.length()) %7B%0A            cStr1 = str1.toCharArray();%0A            cStr2 = str2.toCharArray();%0A        %7D else %7B%0A            cStr1 = str2.toCharArray();%0A            cStr2 = str1.toCharArray();%0A        %7D%0A        len1 = cStr1.length;%0A        len2 = cStr2.length;%0A        max = new int%5Blen1%5D;%0A        maxIndex = new int%5Blen1%5D;%0A        c = new int%5Blen2%5D;%0A%0A        max%5B0%5D = -1;%0A        for(int i = 0; i %3C len2; ++i) %7B%0A            c%5Bi%5D = 0;%0A        %7D%0A%0A        for (int i = 0; i %3C len1; ++i) %7B%0A            for (int j = len2-1; j %3E= 0; --j) %7B%0A                if (cStr1%5Bi%5D == cStr2%5Bj%5D) %7B%0A                    if ((i == 0) %7C%7C (j == 0))%0A                        c%5Bj%5D = 1;%0A                    else%0A                        c%5Bj%5D = c%5Bj - 1%5D + 1;%0A                %7D else %7B%0A                    c%5Bj%5D = 0;%0A                %7D%0A                if (c%5Bj%5D %3E max%5B0%5D) %7B%0A                    max%5B0%5D = c%5Bj%5D;%0A                    maxIndex%5B0%5D = j;%0A                    for (int k = 1; k %3C len1; ++k) %7B%0A                        max%5Bk%5D = 0;%0A                        maxIndex%5Bk%5D = 0;%0A                    %7D%0A                %7D else if (c%5Bj%5D == max%5B0%5D)%7B%0A                    for (int k = 1; k %3C len1; ++k) %7B%0A                        if (max%5Bk%5D == 0) %7B%0A                            max%5Bk%5D = c%5Bj%5D;%0A                            maxIndex%5Bk%5D = j;%0A                            break;%0A                        %7D%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A%0A        for (int i = 0; i %3C len1; ++i) %7B%0A            if (max%5Bi%5D %3E 0) %7B%0A                System.out.println(%22%E7%AC%AC%22 + (i + 1) + %22%E4%B8%AA%E5%85%AC%E5%85%B1%E5%AD%90%E4%B8%B2:%22);%0A                for (int j = maxIndex%5Bi%5D - max%5Bi%5D+1; j %3C= maxIndex%5Bi%5D; ++j)%0A                    System.out.print(cStr2%5Bj%5D);%0A                System.out.println(%22 %22);%0A            %7D%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        String str1 = %22123456abcdddd567%22;%0A        String str2 = %22234dddabc45678%22;%0A        getLCString(str1, str2);%0A    %7D%0A%7D%0A

add fiels