91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 1.11MB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2023-08-09
  • 語言: C/C++
  • 標簽:

資源簡介

用比較簡單的方法實現(xiàn)代碼相似度的計算!

資源截圖

代碼片段和文件信息

/*
對于兩個C++語言的源程序代碼,用哈希表的方法分別統(tǒng)計兩個程序中使用C++語言關(guān)鍵字的情況,
并最終按定量的計算結(jié)果,得出兩份程序的相似性。
基本要求:建立C++語言關(guān)鍵字的哈希表,統(tǒng)計在每個源程序中C++關(guān)鍵字出現(xiàn)的頻度?得到兩個
向量X1和X2,通過計算向量X1和X2的相對距離來判斷兩個源程序的相似性。
例如:??
關(guān)鍵字????????????void???int???for???char??if??else??while??do???break??class
程序1關(guān)鍵字頻度????4?????3??????0?????4?????3????0?????7?????0?????0??????2
程序2關(guān)鍵字頻度????4?????2??????0?????5?????4????0?????5?????2?????0??????1
X1=[4304307002]
X2=[4205405201]
設(shè)s是向量X1和X2的相對距離,s=sqrt(∑(xi1-xi2)^2),當X1=X2時,s=0?反映出可能是同一個程序;
s值越大,則兩個程序的差別可能也越大。
測試數(shù)據(jù):?選擇若干組編譯和運行都無誤的C++程序,程序之間有相近的和差別大的,用上述方法求s?
對比兩個程序的相似性。*/
#include
#include
#include
#include
#include
#define?M?100000
using?namespace?std;
int?hash1[20]hash2[20];
int?fileProcessed(char?sourceData[]int?count);
void?calcunum(char?data[]int?nint?num);
double?possibality(int?hash1[]int?hash2[]);
int?main()
{
int?i;
????int?count1=1;//12用于判斷第一個文件或者第二個文件
int?count2=2;
//定義兩個字符數(shù)組,用于存放經(jīng)過處理后的文件的字符
char?sourceData1[M];//第一個字符數(shù)組
????char?sourceData2[M];//第二個字符數(shù)組
count1?=?fileProcessed(sourceData1count1);??//數(shù)組賦值并返回字符個數(shù)
count2?=?fileProcessed(sourceData2count2);
memset(hash10sizeof(hash1));
memset(hash20sizeof(hash2));
calcunum(sourceData1count11);
calcunum(sourceData2count22);
cout<<“break??char???class??do?????else???for????if?????int????void???while“< for(i=0;i<10;i++)
printf(“%-7d“hash1[i]);
cout< for(i=0;i<10;i++)
printf(“%-7d“hash2[i]);
cout< cout<<“相似度為:?“< return?0;
}
int?fileProcessed(char?sourceData[]int?count)
{
if(count?==?1)
{//處理第一個文件
int?i?=?0;
char?chfirst[10];
cout<<“第一個文件的文件名:“< cin>>first;
ifstream?infile(firstios::in);
ofstream?outfile(“firstProcessed.txt“ios::out);
if(!infile)
{
cerr<<“open?first?error“< }
if(!outfile)
{
cerr<<“open?firstProcessed?error“< }
//處理文件即將()[]{}替換為空格保存在firstProcessed中
while(infile.get(ch))
{
if(ch?==?‘(‘?||?ch?==?‘)‘?||?ch?==?‘{‘?||?ch?==?‘}‘?||?ch?==?‘[‘?||?ch?==?‘]‘)
{
ch?=?‘?‘;
}
if(ch?==?‘‘?||?ch?==?‘<‘?||?ch?==?‘>‘||ch==‘;‘)
{
ch?=?‘?‘;
}
outfile.put(ch);
}
infile.close(); outfile.close();
ifstream?infile2(“firstProcessed.txt“ios::in);//打開firstProcessed需要比較的第一個文件
if(!infile2)
{
cerr<<“open?firstProcessed?error!“< }
???????//把文件存儲在sourceData數(shù)組里并進行進一步處理把多個空格合并為一個空格以減少空間開銷
while(infile2.get(ch))
{
if(ch?==?‘?‘?&&?sourceData[i?-?1]?==?‘?‘)
{
continue;//取消連續(xù)的空格
}
else?if(ch?==?‘\n‘?&&?sourceData[i?-?1]?==?‘\n‘)
{
continue;//取消連續(xù)的空行
}
else
{
sourceData[i++]=?ch;
}
}
count?=?i;?infile2.close();
return?count;
}
else
{
int?i?=?0;
char?chsecond[10];
cout<<“第二個文件的文件名:“< cin>>second;
ifstream?infile(secondios::in);
ofstream?outfile(“secondProcessed.txt“ios::out)

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-07-02?14:10??c++程序?qū)崿F(xiàn)c++代碼相似度計算\
?????文件????????1621??2016-07-02?10:59??c++程序?qū)崿F(xiàn)c++代碼相似度計算\1.txt
?????文件????????1639??2016-07-02?10:59??c++程序?qū)崿F(xiàn)c++代碼相似度計算\2.txt
?????文件????????1848??2009-12-30?15:29??c++程序?qū)崿F(xiàn)c++代碼相似度計算\3.txt
?????目錄???????????0??2016-07-02?12:07??c++程序?qū)崿F(xiàn)c++代碼相似度計算\Debug\
?????文件??????581715??2016-07-02?12:07??c++程序?qū)崿F(xiàn)c++代碼相似度計算\Debug\hua.exe
?????文件??????829972??2016-07-02?12:07??c++程序?qū)崿F(xiàn)c++代碼相似度計算\Debug\hua.ilk
?????文件??????297946??2016-07-02?12:07??c++程序?qū)崿F(xiàn)c++代碼相似度計算\Debug\hua.obj
?????文件?????2148984??2016-07-02?10:59??c++程序?qū)崿F(xiàn)c++代碼相似度計算\Debug\hua.pch
?????文件?????1139712??2016-07-02?12:07??c++程序?qū)崿F(xiàn)c++代碼相似度計算\Debug\hua.pdb
?????文件???????74752??2016-07-02?12:10??c++程序?qū)崿F(xiàn)c++代碼相似度計算\Debug\vc60.idb
?????文件??????110592??2016-07-02?12:07??c++程序?qū)崿F(xiàn)c++代碼相似度計算\Debug\vc60.pdb
?????文件????????1621??2016-07-02?12:10??c++程序?qū)崿F(xiàn)c++代碼相似度計算\firstProcessed.txt
?????文件????????5491??2016-07-02?12:07??c++程序?qū)崿F(xiàn)c++代碼相似度計算\hua.cpp
?????文件????????3365??2016-07-02?12:10??c++程序?qū)崿F(xiàn)c++代碼相似度計算\hua.dsp
?????文件?????????531??2016-07-02?14:10??c++程序?qū)崿F(xiàn)c++代碼相似度計算\hua.dsw
?????文件???????41984??2016-07-02?14:10??c++程序?qū)崿F(xiàn)c++代碼相似度計算\hua.ncb
?????文件???????48640??2016-07-02?14:10??c++程序?qū)崿F(xiàn)c++代碼相似度計算\hua.opt
?????文件?????????240??2016-07-02?12:10??c++程序?qū)崿F(xiàn)c++代碼相似度計算\hua.plg
?????文件????????1848??2016-07-02?12:10??c++程序?qū)崿F(xiàn)c++代碼相似度計算\secondProcessed.txt

評論

共有 條評論