📄 字面相似.txt
字号:
// myclass13.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
float sim_string(string a,string b)
{
int k=0,i,j;
float partone,parttwo=0.0,sim;
int m=a.length(),n=b.length();
int *check_b=new int[n];
for(j=0;j<n;j++)
check_b[j]=0;
int **d=new int*[m];
for(i=0;i<m;i++)
d[i]=new int[n];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
d[i][j]=0;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(a[i]==b[j]&&check_b[j]==0)
{
k++,check_b[j]=1,d[i][j]=1;
}
}
}
/*for(j=0;j<n;j++)
cout<<check_b[j]<<endl;*/
//cout<<m<<endl<<n<<endl<<k<<endl;
partone=(float)k/(m+n-k);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
if(d[i][j]==1)
{
float temp=(float)1/(1+abs(j-i));
parttwo+=temp;
}
}
sim=0.6*partone+0.4*parttwo;
return sim;
delete[] check_b;
for(i=0;i<=m;i++)
delete[] d[i];
delete[] d;
}
int main(int argc, char* argv[])
{
string a="cd",b="dc";
cout<<sim_string(a,b)<<endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -