Color gemstone necklace (ring linked list processing)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.