#K49127. Sort Photos by Year
Sort Photos by Year
Sort Photos by Year
You are given a list of photo filenames. Each filename is in the format YYYY_description.jpg where YYYY represents the year the photo was taken. Your task is to sort these filenames in ascending order by the year.
If two photos have the same year, they should be sorted lexicographically (i.e. in dictionary order) by their full filename.
For example, given the filenames 2021_vacation.jpg
, 2019_birthday.jpg
, and 2021_graduation.jpg
, the sorted order is 2019_birthday.jpg
, 2021_vacation.jpg
, and 2021_graduation.jpg
.
The year can be considered as an integer $YYYY$ extracted from the first 4 characters of the filename.
inputFormat
The first line contains an integer n, the number of photo filenames. The following n lines each contain a photo filename in the format "YYYY_description.jpg".
outputFormat
Output the sorted list of photo filenames, each on a new line.## sample
1
2023_event.jpg
2023_event.jpg
</p>