StringSegment
SRM 320 · 2006-09-30 · by lyc1977
SRM 320 · 2006-09-30 · by lyc1977 · String Manipulation
Problem Statement
Problem Statement
A string is considered to be a composite of several maximal segments of identical characters. For example, "aaabbaaac" is a composite of the segments: "aaa", "bb", "aaa" and "c". Given a string, return the average length of all the segments which form that string.
Notes
- A return value with either an absolute or relative error of less than 1.0E-9 is considered correct.
Constraints
- s will contain between 1 and 50 characters, inclusive.
- s will contain only lowercase letters ('a'-'z').
Examples
0)
"aaabbaaac" Returns: 2.25
Average length of all the segments = ( 3 + 2 + 3 + 1 ) / 4 = 2.25
1)
"aabbccdd" Returns: 2.0
2)
"abba" Returns: 1.3333333333333333
3)
"a" Returns: 1.0
4)
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" Returns: 50.0
Submissions are judged against all 66 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class StringSegment with a public method double average(string s) · 66 test cases · 2 s / 256 MB per case