个人项目作业-论文查重
需求分析
设计一个论文查重算法,给出一个原文文件和一个在这份原文上经过了增删改的抄袭版论文的文件,在答案文件中输出其重复率
实现思路
实现代码
点击查看代码
#define _CRT_SECURE_NO_WARNINGS
#include<stdlib.h>
#include<stdio.h>
#include <string.h>
float similar(char* str1, char* str2)//得到两个字符串里相同字符的个数的函数
{
int n = strlen(str1);
int m = strlen(str2);
int i=0,j=0;
int ret=0;
for (i = 0; (i <= n)&&(j<=m); i++,j++)
{
if (str1[i] == str2[j])
{
ret++;
}
}
return (float)ret/(float)m;
}
int main()
{
char str1[1024], str2[1024];//用于暂存文件里的内容
char a[50], b[50];//存放文件地址
FILE* fp1, * fp2;
float x = 0;
int count = 0;
printf("请输入文本1的地址:");
scanf("%s", a);
if ((fp1 = fopen(a, "r")) == NULL)//判断原文本是否为空文本
{
printf("NOT FOUND!\n");
return -1;
}
printf("请输入文本2的地址:");
scanf("%s", b);
if ((fp2 = fopen(b, "r")) == NULL)//判断需要查重的文本是否为空文本
{
printf("can't open file!\n");
return -1;
}
while ((fgetc(fp1) != EOF) && (fgetc(fp2) != EOF))
{
for (int i = 0; (i < 1024) && (fgetc(fp1) != EOF) && (fgetc(fp2) != EOF); i++)//取文件字符
{
str1[i] = fgetc(fp1);
str2[i] = fgetc(fp2);
}
x = x + similar(str1, str2);//得到两个文档重复部分的占比,累加再除以重复次数即为整个文件的重复率
count++;//计数重复次数
memset(str1, 0, 1024);//清空内存
memset(str2, 0, 1024);
}
x = 2 * x / count;
fseek(fp2, 0, SEEK_END);//定位到文件的最后面
long length = ftell(fp2);//获得文件的大小
printf("相似度为%.2f\n", x);
printf("数值越接近相似度越接近1\n");
fclose(fp1);
fclose(fp2);
return 0;
}
附录
PSP表格
PSP | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | 40 | 80 |
Estimate | 估计这个任务需要多少时间 | 360 | 420 |
Development | 开发 | 120 | 190 |
Analysis | 需求分析 (包括学习新技术) | 80 | 60 |
Design Spec | 生成设计文档 | ||
Design Review | 设计复审 | 30 | 30 |
Coding Standard | 代码规范 (为目前的开发制定合适的规范) | 50 | 20 |
Design | 具体设计 | 50 | 60 |
Coding | 具体编码 | 50 | 30 |
Code Review | 代码复审 | ||
Test | 测试(自我测试,修改代码,提交修改) | 30 | 30 |
Reporting | 报告 | ||
Test Repor | 测试报告 | ||
Size Measurement | 计算工作量 | ||
Postmortem & Process Improvement Plan | 事后总结, 并提出过程改进计划 |