When doing competitive programming, I often hold two values (such as a person's name and year), and this time it was a problem that could not be solved without using such a data structure, so what is a map? A memo instead of a review. https://atcoder.jp/contests/abc113/tasks/abc113_c
A map, also known as an associative array, is a collection that can hold keys and values (a data structure that can be resized later). Do not allow duplicate keys.
HashMap order is appropriate HashTable key in descending order TreeMap key in ascending order
This time, the number of the prefecture to which the city belongs and the year of birth of the city are given, and considering that the year of birth does not overlap, if you put the year of birth as the key and the prefecture to which you belong as the value in the Treemap, you will be born. Since it is sorted by year, you can update the order for each prefecture in the array. Also, the operation of packing 0s from the left with 6 digits is as follows.
Example
System.out.println(String.format("%06d", 1);
result
000001
Citation, reference https://www.sejuku.net/blog/16055 http://kaworu.jpn.org/kaworu/2008-04-10-2.php
Recommended Posts