#C1792. Hashtag Popularity
Hashtag Popularity
Hashtag Popularity
In this problem, you are given several lines of text. Each line may contain hashtags that follow the regular expression (#\verb!\w+!). Your task is to count the frequency of each hashtag in every line, then output the hashtags sorted by descending frequency. If two hashtags have the same frequency, the one with the lower lexicographical order comes first. The result for each line should consist of hashtag-frequency pairs, where each pair is formatted as ( ) and pairs are separated by a single space. If a line does not contain any hashtags, output an empty line.
inputFormat
The input begins with an integer (N) that denotes the number of lines. This is followed by (N) lines of text, each of which may contain one or more hashtags.
outputFormat
Output exactly (N) lines. For each input line, output the hashtag-frequency pairs in sorted order: first by descending frequency and then by lexicographical order if frequencies are equal. Each pair should be formatted as ( ) and pairs should be separated by a space. For lines without hashtags, output an empty line.## sample
1
i love the #weather it is really #nice today #weather #sunny
#weather 2 #nice 1 #sunny 1
</p>