-
打开两个C或C++或其它程序语言文件,并显示两个文件内容;
-
对比两个程序语言源文件,进行重复率检查,给出重复率;注:重复率:连续有n个词相同则计一次重复,n可以通过界面设置进行调整,给出程序设计过程中重复率的设定及计数公式。
-
两个文件中重复之处用红色标出或者摘录出来,注释部分不计重复率。
-
编程语言自行选择,界面自行设计,要求有n设置,有重复率显示结果。
import re
with open("D:\jiancha.txt",encoding='utf-8') as file1:
str1=file1.read()
with open("D:\duibi.txt",encoding='utf-8') as file2:
str2=file2.read()
def YuChuLi(strs):
list1=[]
i=0
while i <len(strs):
if strs[i]=='/' and strs[i+1]=='*':
j=i
while j <len(strs)-1:
if strs[j]=='*' and strs[j+1]=='/':
list1.append(strs[i:j+2])
i=j
break
else:j+=1
else:i+=1
strs=strs.replace('(',' ').replace(')',' ').replace(',',' ').replace(';',' ').replace('{',' ').replace('}',' ')
list2=strs.split()
for l in list1:
if l in list2:
list2.remove(l)
return list2
list1=YuChuLi(str1)
list2=YuChuLi(str2)
n=int(input("请输入n的值:"))
count=0
i=0
while i+n<len(list1):
j=0
while j+n <len(list2):
if list1[i:i+n] == list2[j:j+n]:
count+=1
print("\033[0;31m{}\033[0m".format(list1[i:i+n]))
i=i+n-1
# j=j+n-1
break
else:
j+=1
i += 1
print('\n',count)
print("重复率:{:.4f}%".format(100*n*count/len(list1)))