#C11191. Majority Hashtag Finder
Majority Hashtag Finder
Majority Hashtag Finder
You are given multiple test cases, each representing a series of social media posts. Each post contains one or more hashtags separated by spaces. A hashtag is defined as a word that starts with the #
symbol.
Your task is to determine the "popular" hashtag for each test case. A hashtag is considered popular if it appears in more than \(\frac{n}{2}\) posts, where \(n\) is the number of posts in that test case. If no hashtag satisfies this condition, output NO POPULAR HASHTAG
.
Example:
Input: 3 #food #yummy #food #travel #travel #food</p>Output: #food
In the example above, the hashtag #food
appears in all 3 posts, which is more than \(\frac{3}{2} = 1.5\) posts, and hence it is the popular hashtag.
inputFormat
The input consists of multiple test cases. For each test case, the first line contains an integer \(n\) (\(n > 0\)) representing the number of posts. The following \(n\) lines each contain a string representing the hashtags in one post. The input terminates with a test case where the first line is 0; this test case should not be processed.
All input is read from standard input (stdin
).
outputFormat
For each test case, print the most popular hashtag on a separate line. If no hashtag appears in more than \(\frac{n}{2}\) posts, print NO POPULAR HASHTAG
. Output is written to standard output (stdout
).
3
#food #yummy
#food #travel
#travel #food
#food
</p>