Tag: Col Class log means question preserves AAA output style
A string of lowercase letters can be considered as the largest fragment of some same letter. For example, "AAABBAAAC" is made up of the following fragments: ' aaa ', ' BB ', ' C '. Bull Ox now given a string, please help calculate the average length of all fragments of this string.
Input Description:
The input includes a string s, the length of the string s (1≤length≤50), and S contains only lowercase letters (' a '-' Z ')
Output Description:
Outputs an integer that represents the average length of all fragments, rounded to preserve two decimal places. As shown in the example: s = "AAABBAAAC" The average length of all fragments = (3 + 2 + 3 + 1)/4 = 2.25
Input Example 1:
Aaabbaaac
Output Example 1:
2.25
1num =input ()2result = []3size = Len (num)-14Count = 15 forIinchRange (size):6 ifNum[i] = = num[i+1]:7Count + = 18 Else:9 result.append (count)TenCount = 1 One result.append (count) A Print('%.2f'% (sum (result)/len (result)))
"Python exercises" string fragment