资源简介
该程序主要功能可分为
1.为用户在本地建立一个文本文件,并且支持录入换行功能,字符序列构成且区分大小写
2.统计给定单词在文本文件中出现的次数
3.检索输出某个单词某个单词出现在文本中的行号、在改行中出现的次数以及位置。

代码片段和文件信息
#include
#include
#include
#define MaxStrSize 100
using namespace std;
class Word
{
public:
Word(){text[0]=‘\0‘;}
int Getlength()const;
void PlaceVocabulary();
char text[MaxStrSize];
};
void GetFailure(const Word &patint f[])
{
int j=0k=-1;
f[0]=-1;
while(j if(k==-1||pat.text[k]==pat.text[j])
f[++j]=++k;
else
k=f[k];
}
int KMP_find(Word obWord patint p=0)//p是用于下次匹配的开始检索位置
{
int *f=new int[pat.Getlength()];
GetFailure(patf);
int i=pj=0;
while(i {
if(j==-1||pat.text[j]==ob.text[i])
{
i++;
j++;
}
else
j=f[j];
}
delete []f;
if(j return -1;
else
return i-j;
}
void WordCount()
{
Word obpat;
char filename[10];
ifstream infile;
int i=0jk;
cout<<“Place input flie name:“;
cin>>filename;
cout<<“Place input vocabulary:“;
cin>>pat.text;
infile.open(filename);
while(infile)
{
infile.getline(ob.textMaxStrSize);
k=0;
while(k {
j=KMP_find(obpatk);
if(j<0) break;
else
{
i++;
k=j+ob.Getlength();
}
}
}
infile.close();
cout< cout<<“在文本文件:“< }
void WordRetrieval()
{
Word obpat;
char filename[20];
int ijkl=0m;
int wz[20];
ifstream infile;
cout<<“Place text file name:“;
cin>>filename;
cout<<“Place you need retrieval:“;
cin>>pat.text;
infile.open(filename);
while(infile)
{
infile.getline(ob.textMaxStrSize);
l++;k=0;i=0;
while(k {
j=KMP_find(obpatk);
if(j<0) break;
else
{
i++;
wz[i]=j;
k=j+ob.Getlength();
}
}
if(i>0)
{
cout<<“所在行:“< cout<<“在该行出现的位置分别是:“;
for(m=1;m<=i;m++) cout< cout< }
}
infile.close();
}
void Word::PlaceVocabulary()
{
cout<<“Place input text:“< cin>>text;
}
int Word::Getlength() const
{
int i;
i=0;
while(text[i]!=‘\0‘)
{
i++;
}
return i;
}
void Menu()
{
cout<<“=======================================“< cout<<“文本文件单词的检索和计数系统“< cout<<“=======================================“< cout<<“1.建立文本文件“< cout<<“2.统计单词出现次数“< cout<<“3.检索单词“< cout<<“4.退出“< cout<<“请输入你的选择<1234>:“;
}
void CreateText()
{
Word Textend;
char TextName[100];
end.text[0]=‘/‘;
end.text[1]=‘e‘;
end.text[2]=‘n‘;
end.text[3]=‘d‘;
end.text[4]=‘\0‘;
cout<<“请输入文件名:“;
cin>>TextName;
ofstream outfile(TextNameios::out);
if(!outfile)
{
cerr<<“open error!“< }
cout<<“请输入文本内容:(写完后用/end结束输入)“<
while(KMP_find(Textend)==-1)
{
cin>>Text.text;
if(KMP_find(Textend)==-1)
for(int i=0;i outfile<<‘\n‘;
}
outfile.close();
cout<<“T
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-06-29 18:59 Work\
目录 0 2017-06-29 18:57 Work\Debug\
文件 581687 2017-06-30 09:44 Work\Debug\StringKMP.exe
文件 826920 2017-06-30 09:44 Work\Debug\StringKMP.ilk
文件 381160 2017-06-30 09:44 Work\Debug\StringKMP.obj
文件 2089208 2017-06-30 09:44 Work\Debug\StringKMP.pch
文件 1147904 2017-06-30 09:44 Work\Debug\StringKMP.pdb
文件 115712 2017-06-30 09:44 Work\Debug\vc60.idb
文件 118784 2017-06-30 09:44 Work\Debug\vc60.pdb
文件 3414 2017-06-30 10:04 Work\StringKMP.cpp
文件 3437 2017-06-30 09:44 Work\StringKMP.dsp
文件 524 2017-06-30 10:04 Work\StringKMP.dsw
文件 50176 2017-06-30 10:04 Work\StringKMP.ncb
文件 48640 2017-06-30 10:04 Work\StringKMP.opt
文件 1269 2017-06-30 09:44 Work\StringKMP.plg
文件 28 2017-06-30 09:59 Work\asd.txt
相关资源
- SVR算法程序可运行
- 计算机图形学 边填充算法实现代码
- VisualStudioUninstaller vs卸载工具
- 组态王驱动开发包3.0.0.7(中文)
- 多窗口后台鼠标连点器
- 使用选择性重传协议实现UDP可靠通信
- 福建师范大学历年算法考卷
- 栈的实现及应用,六种基本算法
- Bresenham算法绘制线段并利用“橡皮筋
- 介绍几种压缩算法及《笨笨数据压缩
- VC 获得文件属性 获取文件的创建时
- 改进的BP神经网络算法
- 读者写者问题(读者优先,写者优先
- A星算法_原理讲解_例子
- 云模型的相关算法cloud
- 旋转矩阵求欧拉角的简单算法
- 用VC 编写的仿QQ聊天室程序源代码
- 栅栏填充算法源码(VC)
- RSA算法源码
- 关联分析Apriori算法实现
- [免费]relax算法成像
- 外点法程序
- 外罚函数程序
- qt-电子点菜系统
- 操作系统 LRU算法 实验报告 及 程序代
- 分治法快速排序算法QuickSort C
- 现代谱估计算法 music ESPRIT 谐波分解
- 推箱子及人工智能寻路C 源代码
- 自己写的航空订票系统c 版--数据结构
- 数据结构实验魔王语言
评论
共有 条评论