Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 7361 Accepted Submission (s): 2622
problem DescriptionHomer:marge, I just figured out a-to discover some of the talents we weren ' t aware we had.
Marge:yeah, what's it?
Homer:take me for example. I want to find out if I had a talent in politics, OK?
Marge:ok.
Homer:so I Take some politician's name, say Clinton, and try to find the length of the longest prefix
In the Clinton ' s name is a suffix in my name. That's how close I'm to being a politician like Clinton
marge:why on Earth choose the longest prefix a suffix???
Homer:well, our talents is deeply hidden within ourselves, Marge.
Marge:so How close is you?
homer:0!
marge:i ' m not surprised.
homer:but know, you must has some real math talent hidden deep in.
marge:how come?
Homer:riemann and Marjorie gives 3!!!
marge:who The heck is Riemann?
homer:never mind.
Write A program this, when given strings S1 and S2, finds the longest prefix of S1, which is a suffix of S2.
InputInput consists of lines. The first line contains S1 and the second line contains S2. Assume all letters is in lowercase.
OutputOutput consists of a single line this contains the longest string is a prefix of S1 and a suffix of S2, followed By the length of this prefix. If the longest such string is the empty string and then the output should be 0.
The lengths of S1 and S2 'll be in most 50000.
Sample InputClintonhomerriemannmarjorie
Sample Output0rie 3
SourceHDU 2010-05 Programming Contest
recommendLCYChange a a , a string, in the original B-string matches the original a string prefix, if now a string the last match length is greater than 0, the description can be matched to. here, starting from 0 to save the string, processing the data is always offset a bit ...
1 /*by Silvern*/2#include <algorithm>3#include <iostream>4#include <cstring>5#include <cstdio>6#include <cmath>7 using namespacestd;8 Const intmxn=60000;9 intNXT[MXN];Ten intF[MXN]; One CharA[MXN],B[MXN]; A intla,lb; - voidGetNext () { - inti,j=-1; thenxt[0]=-1; - for(i=1; i<lb;i++){ - while(j>=0&& b[j+1]!=b[i]) j=Nxt[j]; - if(b[j+1]==b[i]) J + +; +nxt[i]=J; - } + return; A } at intMain () { - while(SCANF ("%s%s", b,a)! =EOF) { -La=strlen (a); -lb=strlen (b); - GetNext (); - inti,j=-1; in for(i=0; i<la;i++){ - while(j>=0&& b[j+1]!=a[i]) j=Nxt[j]; to if(b[j+1]==a[i]) J + +; +f[i]=J; - } the if(f[la-1]==-1){ *printf"0\n"); $ }Panax Notoginseng Else{ - for(i=0; i<=f[la-1];i++) printf ("%c", B[i]); theprintf"%d\n", f[la-1]+1); + } A } the return 0; +}
HDU2594 Simpsons ' Hidden talents