背景: #EDF0F5 #FAFBE6 #FFF2E2 #FDE6E0 #F3FFE1 #DAFAF3 #EAEAEF 默认  
阅读新闻

[250分]ReverseSubstring

[日期:2005-12-13] 作者:GoogleCodeJam [字体: ]

Problem Statement
   
You are given a string input. You are to find the longest substring of input such that the reversal of the substring is also a substring of input. In case of a tie, return the string that occurs earliest in input.
Definition
   
Class:
ReverseSubstring
Method:
findReversed
Parameters:
string
Returns:
string
Method signature:
string findReversed(string input)
(be sure your method is public)
   

Notes
-
The substring and its reversal may overlap partially or completely.
-
The entire original string is itself a valid substring (see example 4).
Constraints
-
input will contain between 1 and 50 characters, inclusive.
-
Each character of input will be an uppercase letter ('A'-'Z').
Examples
0)

   
"XBCDEFYWFEDCBZ"
Returns: "BCDEF"
We see that the reverse of BCDEF is FEDCB, which appears later in the string.
1)

   
"XYZ"
Returns: "X"
The best we can do is find a one character substring, so we implement the tie-breaker rule of taking the earliest one first.
2)

   
"ABCABA"
Returns: "ABA"
The string ABA is a palindrome (it's its own reversal), so it meets the criteria.
3)

   
"FDASJKUREKJFDFASIREYUFDHSAJYIREWQ"
Returns: "FDF"

4)

   
"ABCDCBA"
Returns: "ABCDCBA"
Here, the entire string is its own reversal.

阅读:
打印
上一篇:[750分]WordPath
下一篇:[250分]BusStops