#10262 - SuffidromesSolved By: | wesley | Theory Difficulty: | medium | Coding Difficulty: | easy | Algorithms Used: | brute force strings
| Solution Description: | Try all reversed prefixes of each string as possible suffixes, in order of increasing length, and lexicographic earliness. So, for the input:
andrew
wesley
Try "", "a", "w", "ew", "na", "dna", "sew", etc.
For each suffix, try appending it to both strings. If it turns only one into a palindrome, then that's your answer.
If at the end you find no solution, there's one more step to try. We may have a case like:
a
<blank line>
In this case, the solution is "b". Or we might have:
a
aa
In this case, "ba" is the correct suffix.
Let S1 be the smaller string, and S2 be the larger string. If both are the same length, then it doesn't matter which you pick. Try 26 more suffixes, "a"+rev(S1) through "z"+rev(S1), where rev(S1) is S1 reversed.
If there are still no solutions after this step, then print "No solution." |
Copyright 2008 (c) QuestToSolve.Com - Graphs Powered By
|