close
Content

測資有若干行字串。

每個字串是由小寫字母組成。

請找出字串中最長連續的字母,並輸出其長度。

如果有長度相同的連續字母,請輸出最先出現的。

Input
 
Output
 
Sample Input #1
abbcc
cciiiiiiiixxxxxxxxxxxxguuuuuuufugpccccccc
Sample Output #1
b 2
x 12
from sys import stdin
for s in stdin:
    r=[]
    id=0
    s=s.strip()
    len1=len(s)
    idc=0
    while(s):
        c=s[0]
        s=s.lstrip(c)#去左邊的字,他會消掉所有的字
        len2=len(s)
        r.append([c,len1-len2,idc])
        idc+=1
        len1=len2
    r.sort(key=lambda x:(-x[1],x[2]))
    print(r[0][0],r[0][1])
        

 

 

 

arrow
arrow
    文章標籤
    python 高中生程式解題
    全站熱搜
    創作者介紹
    創作者 趴趴熊日常 的頭像
    趴趴熊日常

    資工趴趴熊的小天地

    趴趴熊日常 發表在 痞客邦 留言(0) 人氣()