#CT0000069. Đại diện đầu tiên theo độ dài (First Representative for Each Word Length)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Đại diện đầu tiên theo độ dài (First Representative for Each Word Length)
First Representative for Each Word Length
Problem Statement
A word is a nonempty consecutive sequence of English letters (A–Z, a–z) or digits (0–9). Words are separated by one or more ASCII spaces. Leading/trailing spaces do not create empty words.
Number the words of from in order of appearance. For each word length occurring in the input, determine the first word of length , its position in the word sequence, and the total number of length- words.
Preserve the representative's original capitalization and digits.
Input
- One line contains a string with at least one word. It may have leading or trailing spaces.
Output
- Print , the number of distinct lengths.
- For each length in increasing order, print , , , : the length, its first representative word, the representative's 1-based position, and the total number of words of that length.
Subtasks
-
The string contains only English letters, digits and ASCII spaces.
-
Subtask 1 (25%): ; exactly one separating space, with no leading/trailing spaces.
-
Subtask 2 (35%): ; repeated spaces allowed; each word is at most characters long.
-
Subtask 3 (40%): ; no additional restrictions.
Examples
Example 1
Input
Ky thi HSG THCS 2026 thi
Output
3
2 Ky 1 1
3 thi 2 3
4 THCS 4 2
Explanation
The six words are Ky (length ), thi (), HSG (), THCS (), 2026 (), and thi (). The first representative for length is Ky at position (frequency ); for length , thi at position (frequency ); and for length , THCS at position (frequency ). Print these three groups by increasing length.
Example 2
Input
aa b cccc dd e
Output
3
1 b 2 2
2 aa 1 2
4 cccc 3 1
Explanation
The word lengths are . For length , the first word is b at position and the frequency is . For length , use aa at position and frequency . For length , use cccc at position and frequency . Print the groups in length order .
Example 3
Input
x yy zzzzz y
Output
3
1 x 1 2
2 yy 2 1
5 zzzzz 3 1
Explanation
Ignoring repeated spaces gives the word sequence x, yy, zzzzz, y, with lengths . Length occurs twice, and its first representative is x at position . Lengths and each occur once, with representatives yy and zzzzz.