aboutsummaryrefslogtreecommitdiff
path: root/challenge-329/eric-cheung/python/ch-2.py
blob: 572cf81fcc674649d99a2b2c36d990159629e805 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def IsStrNice (strFunc):
    arrFunc = set(list(strFunc))
    strChar = strFunc[0]
    return strChar.upper() in arrFunc and strChar.lower() in arrFunc

## strInput = "YaaAho"  ## Example 1
## strInput = "cC"  ## Example 2
strInput = "A"  ## Example 3

arrTemp = []
strTemp = strInput[0]

for charLoop in strInput[1:]:
    if charLoop.lower() == strTemp[-1].lower():
        strTemp = strTemp + charLoop
    else:
        arrTemp.append(strTemp)
        strTemp = charLoop

arrTemp.append(strTemp)

nMaxLen = 0
arrOutput = []

for strLoop in arrTemp:
    if not IsStrNice(strLoop):
        continue

    if len(strLoop) < nMaxLen:
        continue

    if len(strLoop) > nMaxLen:
        nMaxLen = len(strLoop)
        arrOutput = [strLoop]
    else:
        arrOutput.append(strLoop)

print (", ".join(arrOutput))