Homer: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 Clinton ' s name t Hat 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. |
Homer: Maggie, it suddenly occurred to me that there was a way to explore our potential. Maggie: Well, what's that? Homer: For example I want to know if I have the potential to wade officialdom ... Maggie: Yes. Homer: So I wrote a politician's name, like Clinton, and then found the maximum length of the prefix of his name that matched my name suffix. It means how much I want to be a politician like Clinton. Maggie: So why on earth is the longest prefix suffix??? Homer: After all, everyone is a real luxiang, Maggie. Maggie: What about your results? Homer: 0! Maggie: no surprise. Homer: But I know, you must have a potential mathematical talent. Maggie: Where did you get that? Homer: Riemann and Marjorie match 3!!! Maggie: Who is Riemann? Homer: I don't understand. Tap a program, for the given string S1 and S2, find the maximum matching length of the S1 prefix with the S2 suffix. |