#C14663. Filter and Sort Users
Filter and Sort Users
Filter and Sort Users
You are given a list of users. Each user is described by three fields: an integer id
, a string name
, and an integer age
.
Your task is to filter out all users whose age is strictly less than 18 and then sort the remaining users in ascending order by their age. Finally, print each remaining user's id
and name
in separate lines.
Formally, if you are given N
users, the input is in the following format:
- The first line contains the integer \(N\), the number of users.
- The following \(N\) lines each contain three space-separated values:
id
(an integer),name
(a string without spaces), andage
(an integer).
The output should list the filtered users (those with \(age \ge 18\)) sorted by age in ascending order. For each user, output the id
and name
separated by a space on a single line.
Note: If there are no users aged 18 or above, the program should produce no output.
inputFormat
The input will begin with an integer N
(\(1 \leq N \leq 10^5\)), the number of users. Next, there will be N
lines, each containing three space-separated values: an integer id
, a string name
(without spaces), and an integer age
.
outputFormat
For each user with \(age \geq 18\), output a single line with the id
and name
separated by a space in ascending order based on the user's age.
4
1 Alice 17
2 Bob 20
3 Charlie 19
4 David 18
4 David
3 Charlie
2 Bob
</p>