stringmatch.cpp
来自「字符串的模式匹配(KMP算法)」· C++ 代码 · 共 42 行
CPP
42 行
// stringmatch.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "Mstring.h"
#include <fstream>
int main(int argc, char* argv[])
{
while(1){
ifstream infile;
string tstr,sstr;
int line=1,pos=0;
bool flag=false;
cout<<"\nInput the string you want to find:";
cin>>tstr;
Mstring mstr(tstr);
infile.open("stringmatch.cpp");
while(getline(infile,sstr)){
mstr.set_sstr(sstr);
pos=mstr.index_KMP();
if(pos){
cout<<"Found in line "<<line<<",position "
<<pos<<endl;
flag=true;
}
line++;
}
if(!flag) cout<<"Not found!\n";
infile.close();
}
return 0;
}
/*If you intend using humor in your talk to make people smile, you must
knowhow to identify shared experiences and problems. Your humor must
be relevant tothe audience and should help to show them that you are
one of them or that you understand their situation and are in sympathy
with their point of view. Depending on whom you are addressing, the
problems will be different. If you are talking to a group of managers,
you may refer to the disorganized methods of their secretaries;
alternatively if you are addressing secretaries, you may want to
comment on their disorganized bosses.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?