求这个完整的前面密文后面明文的串
# include <stdio.h> # include <algorithm> # include <string.h> using namespace std; int len; int next[100010]; char a1[100010],a2[100010],a3[100010]; void Getnext() { int i=0,j=-1; next[0]=-1; while(i<len) { if(j==-1||a2[j]==a2[i]) i++,j++,next[i]=j; else j=next[j]; } } int KMP() { int len1=strlen(a3); int len2=strlen(a2); int i=0,j=0; while(i<len1&&j<len2) { if(j==-1||a2[j]==a3[i]) { i++;j++; if(i==len1) return j; } else j=next[j]; } return 0; } int main() { int i,j,t; while(~scanf("%d",&t)) { while(t--) { scanf("%s %s",a1,a2); printf("%s",a2); len=strlen(a2); strcpy(a3,a2+(len+1)/2); for(i=0;a2[i];i++)//转化为加密串 { for(j=0;j<26;j++) { if(a2[i]==a1[j]) { a2[i]='a'+j; break; } } } for(i=0;a2[i];i++) printf("%c",a2[i]); Getnext();//a2 int flag=KMP();//a3,a2 for(i=flag;i<len-flag;i++) printf("%c",a2[i]); printf("\n"); } } return 0; }
hdu 4300 Clairewd’s message (KMP),布布扣,bubuko.com
hdu 4300 Clairewd’s message (KMP)
原文:http://blog.csdn.net/lp_opai/article/details/38520739