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])
文章標籤
全站熱搜