Grandpa is Famous!
InterviewTime limit1sMemory limit256 MB
Given weekly ranking lists, count how many times each player appears, then print the players with the second-highest count in ascending order.
- Level
Easy3 of 10
- Topics
- Hash map, Sorting, Implementation, Array
- Solved
- No attempts yet
Problem
After seeing "the news," the whole family got excited. Everyone knew that Grandpa had been an outstanding bridge (a type of card game) player for decades, but the news that he was being entered into the Guinness Book of Records as the greatest bridge player of all time was truly astonishing!
For many years, the International Bridge Association (IBA) has recorded the weekly rankings of the most skilled players. Every time a player's name appears in a week's ranking, that player earns 1 point, and Grandpa earned the most points and was named the greatest bridge player.
Grandpa had many friends who competed with him for the bridge rankings, so he was very curious about which player (or players) came in second place.
The IBA's ranking data is now available online. Write a program that takes the weekly ranking lists as input and determines who the second-place player is.
Input
Each player is identified by an integer (a player number) from to . The input consists of several test cases.
The first line of each test case contains two integers and , meaning that for () weeks, the rankings of the top () players each week are given.
Then lines follow, each describing one week's ranking. Each line contains integers separated by spaces.
- In each test case there is exactly one player with the highest score.
- Each week's ranking contains distinct player numbers.
A line where and are both marks the end of the input.
Output
For each test case, print the number(s) of the second-place player(s) on a single line. If two or more players are tied for second place (a tie), print each player number separated by a space in ascending order.