string EnterPassword(){ //输入密码 string passwordInput=\ char digit='\\0'; while(true){
digit=getch();
switch(digit){ case '\\b': //退格 if (passwordInput.size()){ cout<<\
passwordInput.resize(passwordInput.size()-1);
}
else{cout<<\
case '\\r': //回车 case '\\n': //换行 cout< return passwordInput; break; default: cout<<\ passwordInput.append(&digit,sizeof(char)); } } } void Enter(){ //登录系统 int chance=3; //输入密码的最多次数 14 string password; //用于存储输入的密码 HANDLE hThread=NULL; // 用于调用进度条函数的句柄 DWORD ThreadID=0; // 用于记录线程编号 fflush(stdin); // 刷新键盘缓冲区 system(\清屏 cout<<\cout<<\欢迎来到知识的海洋 *\cout<<\cout<<\你即将进入的是串的模式匹配系统 *\cout<<\登录系统******************\while(chance>0){ //还有机会 cout<<\请输入密码:\ password=EnterPassword(); fflush(stdin); if(password==Password) { //若密码正确 system(\ strcpy(prompt,\请稍等片刻!系统正在进入...\\n\ // 启动进 hThread=CreateThread(NULL,0,ProgBar,0,0,&ThreadID); 度条线程,制作退出界面 WaitForSingleObject(hThread,INFINITE); hThread=NULL; system(\ return; //退出子函数 } else{ //若密码错误 chance--; //机会减一 // 等待进度条线程 15 cout<<\您输入的密码有误,请重新输入!您还有\次机会\ } } cout<<\测试\ //若输入密码的机会已耗尽,则中断运行 system(\ strcpy(prompt,\您是非法用户!\\n\\t\\t\\t系统将自动退出!\\n\hThread=CreateThread(NULL,0,ProgBar,0,0,&ThreadID); 程,制作退出界面 WaitForSingleObject(hThread,INFINITE); 程 hThread=NULL; system(\exit(1); } DWORD WINAPI ProgBar(LPVOID threadNum){ int i,j; system(\for (i=1;i<=20;i++){ system(\ cout< cout<<\┌────────────────────┐\ cout << \│\ // 进度条线程函数 // 启动进度条线 // 等待进度条线 16 for(j=1;j<=i;j++) cout << \■\ for(j=19;j>=i;j--) cout << \ cout << \│\ cout<<\└────────────────────┘\ Sleep(100); } return 0; } ⑵ 串的朴素模式匹配、模式匹配KMP算法、KMP改进算法的实现,具体实现如下: ① void GetNext(SeqString T,int (&next)[64]) {//求模式串T中的next函数值并存入数组next,输出next数组 int j=0,k=-1; next[0]=-1; while(T.ch[j]!='\\0'){ if(k==-1||T.ch[j]==T.ch[k]){ } else } k=next[k]; ++k;++j; if(T.ch[j]!=T.ch[k]) else next[j]=next[k]; next[j]=k; ②void GetNextVal(SeqString T,int(&next)[64]) 17 {//求模式串T中的next函数修正值并存入数组next中 int i,j; i=0;next[1]=j=-1; while(i if(j==-1||T.ch[j]) { } else j=next[j]; ++i;++j; if(T.ch[i]!=T.ch[j]) next[i]=j; else next[i]=next[j]; for(i=0;i printf(\} printf(\if(i%5==0) printf(\ ③ int IndexKMP1(SeqString S,SeqString T,int(&next)[64],int pos) {//利用模式串T的next函数求T在主串S中第pos个字符之后的位置的KMP算法。其中T非空,1= int i,j; i=pos-1;j=0; while(i if(j==-1||S.ch[i]==T.ch[j]) {++i;++j;}//继续比较后继字符 else j=next[j];//模式串向右移动 18