标签:main tchar == highlight log get name getch har
#include <bits/stdc++.h> using namespace std; int fail[1005]; void getline(string &str){ char c=getchar(); while(c==‘\n‘||c==‘\r‘)c=getchar(); while(c!=‘\n‘&&c!=‘\r‘)str+=c,c=getchar(); } int find(string A,string B){ int j=0; for(int i=0;i<A.size();i++){ while(A[i]!=B[j]&&j)j=fail[j]; if(A[i]==B[j])j++; if(j==B.size())return i-j+1; } } void getfail(string A){ for(int i=1;i<A.size()-1;i++){ int j=fail[i]; while(j&&A[i]!=A[j])j=fail[j]; if(A[j]==A[i])fail[i+1]=j+1; } } int main(){ string A,B; getline(A); getline(B); getfail(B); cout<<find(A,B)<<endl; return 0; }
标签:main tchar == highlight log get name getch har
原文地址:http://www.cnblogs.com/HC-LittleJian/p/7501605.html