Description
A colorful gemstone necklace is made up of many different kinds of gems, including Ruby, sapphire, diamond, jadeite and Pearl. One day, the king gave the necklace to a scholar and told him that you could take it away, but the Queen liked rubs, sapphire, Amethyst, jadeite and diamond, I want you to take a small segment from the necklace and return it to me. This section must contain all these five kinds of gems, and you can take the rest. If one cannot be found, it cannot be taken away. Please help scholars find out how to split the necklace to get the most gems.
Input description:
We use each character to represent a kind of gem. A represents Ruby, B Represents sapphire, c Represents Amethyst, D represents jadeite, e Represents diamond, f Represents jadeite, g Represents glass, etc, we use a string of all uppercase letters to represent the sequence of the gemstone of the necklace. Note that the necklace is first and end-to-end. Each row represents a situation.
Output description:
The maximum number of gems that scholars can obtain. One per line
Example 1
Input
Abcydye
Attmbqecpd
Output
1
3
# Import sys # sys. stdin = open('input.txt ', 'R') def judge (S, L, start): temp = s [start: Start + L] If temp. find ('A') =-1 or temp. find ('B') =-1 or temp. find ('C') =-1 or temp. find ('D') =-1 or temp. find ('E') =-1: Return false return truewhile true: Try: S = input () L = Len (s) # print (S, L) S = S + S # Processing ring flag = false for J in range (5, L + 1): # Put the length outside, once found, you can break it. For I in range (l): If Judge (S = s, L = J, start = I): # print (s [I: I + J]) print (L-j) Flag = true break if flag: Break expires T: Break
Color gemstone necklace (ring linked list processing)