#C78. Suggested Posts
Suggested Posts
Suggested Posts
You are given a list of posts. Each post has an id
(an integer) and content
(a string). You are also given a keyword
(string) and an integer N. Your task is to return the top N post IDs for which the content
contains the given keyword
(case-insensitive), sorted in ascending order of their IDs.
The matching rule is defined as follows: a post is considered to match if the lowercase version of its content contains the lowercase version of the keyword. If the number of matching posts is less than N or if N is 0, return an empty list (or print nothing).
The selection can be described by the formula below: \[ \text{Result} = \{ id_i \mid \text{for post } i, \; \text{lower}(content_i) \text{ contains } \text{lower}(keyword) \}\] \]
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer P denoting the number of posts.
- The next P lines each contain a post. Each line starts with an integer
id
, followed by a space and then thecontent
(which may include spaces). - The following line contains the
keyword
(a string). - The last line contains an integer N, representing the maximum number of post IDs to return.
outputFormat
The output is printed to standard output (stdout) as a single line containing the selected post IDs separated by a single space. If no posts match, output an empty line.
## sample4
1 I love programming with Python and JavaScript.
2 Python is an amazing language for data science.
3 JavaScript and frontend frameworks go hand-in-hand.
4 Data science is fascinating.
Python
2
1 2