#CCBCHBON0000027. Đếm dấu cách, tab và dòng mới (Count Spaces, Tabs and Newlines)
Đếm dấu cách, tab và dòng mới (Count Spaces, Tabs and Newlines)
Count Spaces, Tabs and Newlines
Source: Kernighan & Ritchie
Version: Phuoc Hung OJ Extended
Problem Statement
Read the entire text stream until EOF. Count literal space (U+0020), horizontal tab (\t, U+0009) and newline (\n, U+000A) separately. Count actual newline characters only, not an unterminated final line. An empty stream yields three zeros. This PHOJ edition prints counts in space, tab, newline order.
Input
One UTF-8 text stream of at most 100000 bytes; it may be empty, multi-line or have no trailing newline.
Output
Print exactly three integers on one line separated by single spaces: space count, tab count and newline count.
Subtasks
-
Subtask 1 (20%): UTF-8 stream length at most 20 bytes.
-
Subtask 2 (30%): UTF-8 stream length at most 500 bytes.
-
Subtask 3 (50%): UTF-8 stream length at most 100000 bytes.
Examples
Example 1
Input:
A B C
D E
Output:
2 1 2
Explanation:
The actual input contains 2 spaces, 1 tabs and 2 newline characters. Any literal trailing newline is included in the count.
Example 2
Input:
hello
Output:
0 0 0
Explanation:
The actual input contains 0 spaces, 0 tabs and 0 newline characters. EOF occurs directly after the last letter; there is no trailing newline.
Example 3
Input:
Output:
0 0 0
Explanation:
The actual input contains 0 spaces, 0 tabs and 0 newline characters. Any literal trailing newline is included in the count.