1. 用C++编程,对于两个C 语言的源程序代码,分别统计两个程序中使用C 语言关键字的情况,并最终按以下方法实
建议你去看看shell命令differ用C语言的实现过程,专门用来检测两个文件的相似性.
2. 如何用哈希表统计一段代码中出现的关键字的频度
扫描一次 扫到一个关键字 就令 h[key]++; 初始化h数组为0 就可以了
要方便点的话 可以使用C++ STL库中的 map
#include
map m;
using namespace std;
for(i= all of key in your code) m[key]++;
3. 程序源代码的相似性
楼主,有这题的代码么?
4. 一道数据结构的题,基于散列表的程序相近度检测系统 ,回答完后再加分!谢谢了,大神们!
给你答案,给我份
5. 设计一个保留字(或关键字)的统计程序 建立保留字文件; 从源数据文件(C或C++语言程序)中,读取
std::cout<<"C++作业我帮你搞定:QQ:563337217"<<endl;
6. C++高手能不能帮我看下这段程序!是关于哈希统计关键字的.
格式混乱,重新排版,费了好大劲。。。
你第一个函数 少了一个右面的大括号 }
if(first=='/'&&last=='/'&&star&"ation) //这句是什么意思
你自己好好看看吧,就是格式的问题。 下面是我修改完的。
#include
#include
#include
#include
#include
using namespace std;
void printHash();
class Hash
{
public:
int frequency;
string kw;
Hash() {frequency=0;}
};
Hash HashList[41];
int count=0;
bool open=true;
void CreateHash()//创建哈希表
{
ifstream in("keys.dat");
for(string s; getline(in,s); )//逐行将数据读入到s中
{
istringstream sin(s);//创建sin流进行分离
for(string t;sin>>t;)//输入到t中
{
int n=t.size();
int key=((t[0]-96)*100+t[n-1]-96)%41;
if(HashList[key].kw=="")
HashList[key].kw=t;
else
{
while(HashList[key].kw!=t&&HashList[key].kw!="")
{
key++;
if(key>40) key=0;
if(HashList[key].kw=="")
HashList[key].kw=t;
}
}
key=0;
while(HashList[key].kw!=""&&HashList[key].kw!=t)
{
if(HashList[key].kw=="")
HashList[key].kw=t;
}
}
}
}
void printHash ()
{
cout<<"@*****************Hash数组*********************@"<<endl;
cout<<"数组下标"<<" 关键字"<<" 出现频率"<<endl;
for(int i=0;i<41;i++)
cout<<setw(5)<<i<<setw(14)<<HashList[i].kw<<setw(15)<<HashList[i].frequency<<endl;
}
void HashCount (string t) //统计关键字
{
int n=t.size();
int key=((t[0]-96)*100+t[n-1]-96)%41;
while(HashList[key].kw!="")
{
count++;
if(HashList[key].kw==t)
{
HashList[key].frequency++;
key++;
break;
}
else
key++;
if(key>40)
key=0;
}
if(HashList[key].kw=="")
count++;
}
void HashSearch(char *file)//处理注释
{
ifstream in(file);
bool quotation=true;//双引号
bool slash=true;//双斜杠
bool star=true;//杠星
char first=';', last;
string str;
int tag=0;
if(in.is_open())
{
for(string s;getline(in,s);)
{
istringstream sin(s);
for(string t;sin>>t;)
{
int n=t.size();
slash=true;
star=true;
for(int i=0;i<n;i++)
{
last=t[i];
if(first'z')
{
if (first == '/' && last == '/' /* && star & " ation */) // 这行什么意思?
{
slash=false;
cout<<"slash\n";
}
else if(first=='/'&&last=='*')
{
star=false;
cout<<"star\n";
}
else if (first=='*' && last=='/' /*&" ation==false*/)
{
star=true;
}
else if(last='"'/*&"ation==true*/)
quotation=false;
else if( last= '"' /*&" ation==false*/)
quotation=true;
if(slash && star /*&"ation*/ )
{
t[tag++]=last;
HashCount(t);
}
t[tag]='\0';
tag=0;
first=last;
}
}
if(!slash)break;
if( /*star&"ation &&*/ t[tag]=='\0' && tag==0 )
HashCount(t);
}
}
}
}
void printHash_2()
{
cout<<"@*****************Hash查找关键字*********************@"<<endl;
cout<<"数组下标"<<" 关键字"<<" 出现频率"<<endl;
for(int i=0;i<41;i++)
cout<<setw(5)<<i<<setw(14)<<HashList[i].kw<<setw(15)<<HashList[i].frequency<<endl;
cout<<count;
}
void main()
{
CreateHash();
printHash();
HashSearch("file.cpp");
printHash_2();
}
7. 编写一个C++算法frequency,统计输入的一个字符串中各种不同字符出现的频度
有注释,自己看,可续问。main中的char* string;是声明字符指针而并非字符串,要改成char string[100];
//#include "stdafx.h"//vc++6.0加上这一行.
#include
using namespace std;
void frequency(char *str){
char ch[2][100]={0};//要改成ch[2][100]
int i,j;
for(i=0;i<96;ch[0][i]=32+i++);//加这一句初始化数组ch[0]
for(i=0;str[i]!='\0';i++){
for(j=0;ch[0][j]!='\0';j++)//不初始化,ch[0][j]!='\0'就不能满足
if(str[i]==ch[0][j])
ch[1][j]++;
//else{//这几行就用不着了
// ch[0][j]=str[i];
// ch[1][j]++;
//}
}
cout<<"频数统计如下:"<<endl;
for(int k=0;ch[0][k]!='\0';k++)//要改成ch[0][k]
if(ch[1][k])//限制未出现的字符输出
cout<<ch[0][k]<<" "<<(int)ch[1][k]<<endl;//要强制为int,不然输出是字符
}
/*以上是基本按你的思路改的。如果完全按你的思路,看下面的函数,控制复杂一些*/
void frequency(char *str){
char ch[2][100]={0};
int i,j;
ch[0][0]=127;//用这一句先让j的循环转起来
for(i=0;str[i]!='\0';i++){
for(j=0;ch[0][j]!='\0';j++)
if(str[i]==ch[0][j]){
ch[1][j]++;
break;
}
if(ch[0][j]==0){
ch[0][j]=str[i];
ch[1][j]=1;
}
}
cout<<"频数统计如下:"<<endl;
for(i=1;ch[0][i];i++)
cout<<ch[0][i]<<" "<<(int)ch[1][i]<<endl;
}
void main(void){
char string[100];
cout << "请输入一个长度不大于100的字符串:"<<endl;
cin >> string;
frequency(string);
}
8. 跪求!!哪位高手帮帮忙,用C++程序求 保留字(或关键字)统计程序
getline(),CString.Left(' ')...