标签:style blog http color java os io for
clinton homer riemann marjorie
0 rie 3
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define INF 0x3f3f3f3f 15 using namespace std; 16 char sa[50010<<1],sb[50010]; 17 int fail[50010<<1]; 18 void getFail(){ 19 fail[0] = fail[1] = 0; 20 for(int i = 1; sa[i]; i++){ 21 int j = fail[i]; 22 while(j && sa[i] != sa[j]) j = fail[j]; 23 fail[i+1] = sa[i] == sa[j]?j+1:0; 24 } 25 } 26 int main() { 27 int i,j; 28 while(~scanf("%s %s",sa,sb)){ 29 int len = strlen(sa),len2 = strlen(sb),i = len+len2; 30 for(i = len,j = 0; sb[j]; i++,j++) 31 sa[i] = sb[j]; 32 sa[i] = ‘\0‘; 33 getFail(); 34 for(;fail[i] > len || fail[i] > len2; i--); 35 len = strlen(sa); 36 if(fail[i]){ 37 printf("%s %d\n",sa+len-fail[i],fail[i]); 38 }else puts("0"); 39 } 40 return 0; 41 }
BNUOJ 6719 Simpsons’ Hidden Talents,布布扣,bubuko.com
BNUOJ 6719 Simpsons’ Hidden Talents
标签:style blog http color java os io for
原文地址:http://www.cnblogs.com/crackpotisback/p/3903595.html