Organizing Files
InterviewTime limit3sMemory limit1024 MB
Given N file names, count how many files share each extension and print the extensions in lexicographic order with their counts.
- Level
Easy3 of 10
- Topics
- String, Hash map, Sorting, Implementation
- Solved
- No attempts yet
Problem
Sbrus bought a used laptop from a friend, and the moment he turned it on he was appalled. The desktop was packed with all kinds of files, none of them organized. In a corner of the screen he found a message from his friend.
The files on the desktop hold information about a valuable treasure. If you delete even one of them, you will lose the treasure and never be able to use the laptop again. Analyze the files well, and I hope you become the hero who claims the treasure. The hint is "extension".
Sbrus had been angry, but the talk of treasure calmed him down right away, and he worked hard to uncover the treasure's information. There were too many files, though, so he soon gave up and asked for the files to be organized, offering half the treasure as a reward. Sbrus's request is as follows.
- Organize the files by extension and tell me how many there are of each
- Sort the extensions in lexicographic order so they are easy to read
Now let's build a program that organizes the files on Sbrus's laptop so we can get half the treasure!
Input
The first line gives the number of files on the desktop, . ()
The next lines give the names of the files on the desktop. A file name consists only of lowercase English letters and the dot character (.). The dot appears exactly once and is neither the first nor the last character of the file name. Each file name has length at least and at most .
Output
For each extension, print its name and the number of files with that extension, one per line. If there is more than one extension, print them in lexicographic order of the extension names.
Hint
They say the magnificent treasure is the satisfaction of having organized your desktop.