Counting Hashtags
Time limit2sMemory limit1024 MB
Count the distinct hashtags in a text, where a hashtag is a space-separated word that starts with # and has no other #, then print each with its occurrence count.
Problem
Dima is developing a new trendy social network. He wants to write a module that processes text and counts the distinct hashtags in it.
The text consists of lowercase English letters, digits, the character #, and spaces. A word is a run of consecutive non-space characters bounded on the left and right by spaces or by the start or end of the text. A word is a hashtag if its length is at least , its first character is #, and none of its other characters is #.
Dima wants to count the distinct hashtags that occur in the text, print them, and print how many times each one occurs.
Input
A single line contains the text in the format described above. The length of the text does not exceed . The text may contain several spaces in a row, and spaces at the beginning or end of the line.
Output
The first line contains the integer , the number of distinct hashtags in the text. The next lines contain a hashtag and the number of times it occurs. The hashtags may be printed in any order.