#coding:gbk
import os,sys
def lcs(short, long):
m = len(short)
n = len(long)
if (m <= 0 or n <= 0):
return "";
if m>n:
short,long = long,short
if short in long:
return short
t1 = lcs(short[1:],long)
t2 = lcs(short[0:-1],long)
if t1>t2:
return t1
else:
return t2
def main():
if len(sys.argv)<3:
print "使用:lcs <字符串1> <字符串2>"
return
a = lcs(sys.argv[1],sys.argv[2])
print "最大公共子串长度:%d"%len(a)
print "最大公共子串:"+a
if __name__ == '__main__':
main()