#CCBCHBON0000042. Đếm dòng rỗng trong luồng (Count Empty Lines in a Stream)
Đếm dòng rỗng trong luồng (Count Empty Lines in a Stream)
Count Empty Lines in a Stream
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Read the entire ASCII byte stream to EOF. An empty line is a zero-byte line terminated by LF (newline). Count an LF at the beginning of the stream, or an LF immediately following another LF. Space-only and tab-only lines are not empty. An empty file counts as zero; EOF does not create an implicit extra line.
Input
An ASCII stream of 0..100000 bytes (0..127); spaces, tabs, CR and LF are allowed. A trailing LF is optional.
Output
Print the empty-line count followed by LF.
Subtasks
-
Subtask 1 (20%): ASCII stream length 0..100 bytes.
-
Subtask 2 (30%): ASCII stream length 0..2000 bytes.
-
Subtask 3 (50%): ASCII stream length 0..100000 bytes.
Examples
Example 1
Input:
Output:
0
Explanation:
Count only an LF at stream start or immediately after another LF. Exact input: ""; exact output: "0\n".
Example 2
Input:
Output:
1
Explanation:
Count only an LF at stream start or immediately after another LF. Exact input: "\n"; exact output: "1\n".
Example 3
Input:
A
B
Output:
1
Explanation:
Count only an LF at stream start or immediately after another LF. Exact input: "A\n\nB\n"; exact output: "1\n".
Example 4
Input:
A
Output:
3
Explanation:
Count only an LF at stream start or immediately after another LF. Exact input: "\n\nA\n\n"; exact output: "3\n".
Note on displayed bytes: \n denotes an actual LF, \t an actual tab and \r an actual CR. The JSON-style Input renderings in explanations are diagnostic only, not extra input characters.