#P8506. Count Level 1 Markdown Headers
Count Level 1 Markdown Headers
Count Level 1 Markdown Headers
Markdown is a lightweight markup language. In Markdown, if the first non‐whitespace character of a line is a hash sign (#) and it is immediately followed by one or more space characters, then the remaining non‐whitespace content of that line is rendered as a level 1 title.
More formally, let a line (after removing leading whitespace) be denoted as S. Then S represents a level 1 title if and only if:
- S[0] == '#' (i.e. the first character is a hash),
- The character immediately following '#' is a space (i.e. S[1] == ' '),
- There exists at least one non‐space character after the consecutive spaces.
Note that lines such as "## This is a secondary title" or "#You should insert a space" do not qualify as level 1 titles.
inputFormat
The input consists of multiple lines of text (terminated by EOF). Each line may be empty or contain arbitrary characters.
outputFormat
Output a single integer indicating the total number of level 1 markdown headers found in the input text.
sample
# This is a title
This is not a title
# Another title
2