A proofreading pass audits capitalization. Treat every terminator character (., !, ?) as the end of the current segment: scanning the text left to right, each terminator closes the run of characters accumulated since the previous terminator (or the start of the text). Only segments that are actually closed by a terminator are audited; any trailing text after the final terminator is ignored, and an empty segment (two terminators in a row) is ignored.
For each audited segment, find its first alphabetic character (ASCII letter). The segment is a violation if that first letter is lowercase. A segment with no alphabetic character at all is not a violation.
Report the number of violations.
The entire input is the text (it may span several lines).
A single integer: the number of violating segments.
Example 1
Input
Hello there. this is wrong. Great job.
Expected
1
Explanation
Three segments end with a period: 'Hello there' (starts H, ok), ' this is wrong' (first letter t is lowercase, violation), ' Great job' (starts G, ok). One violation.
Example 2
Input
first.
Expected
1
Explanation
The single segment 'first' has first letter f, which is lowercase, so it is one violation.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →