#P8506. 标题计数

标题计数

Background

5ab is trying to help Luogu write a bot to count how many level-1 headings there are in solutions.

Problem Description

Markdown is a markup language. In Markdown, if the first non-whitespace character of a line is a hash sign (#) and it is immediately followed by some spaces, then the remaining non-whitespace content of this line will be rendered as a level-1 heading.

Within the scope of this problem, the following are all level-1 headings:

# This is a title
#    This is another title
    # This is also a title
    #   You#can#add#more#sharps
# #

Within the scope of this problem, the following are NOT level-1 headings:

<h1>an HTML title</h1>
#You should insert a space
## This is a secondary title
aaaaa # This is not a title at all
 # 
You should add something after the sharp sign

Given a piece of multi-line text, find the total number of level-1 headings in it.

Input Format

The first line contains an integer nn, representing the number of lines of the text.

Then nn lines follow, which are the given markup text.

Output Format

Output one line containing one integer, the number of level-1 headings in this text.

1
#u#n#t#i#t#l#e#d#
0
1
# a perfect title
1
10
# a
 # b
## c
#d
#  
e
# f#g#h#i#j
  ##k
# #
l # m
4

Hint

Explanation for Sample 3.

Lines 2, 3, 8, and 10 (lines 1, 2, 7, and 9 in the text) are level-1 headings that meet the conditions.


If a contestant uses Windows during the contest, then the newline characters in the samples copied directly from the website or the distributed statement are CRLF, which may differ from the LF used in the actual testdata. To make debugging easier, it is recommended to test using the samples in the distributed file, and to use file input/output directly.

Constraints

The total text is no more than 100100 characters, and no more than 1010 lines. The text contains only English letters, hash signs (#), newline characters (Line Feed, LF, \n), and spaces.

$$\def\arraystretch{1.5} \begin{array}{|c|c|}\hline \bf{测试点} & \bf{文本特殊性质} \\ \hline 1 & 没有空白字符 \\\hline 2,3& 只有\ 1\ 行 \\\hline 4,5 & / \\\hline \end{array}$$

Translated by ChatGPT 5