BlueBook

p172ex8 - Mode

Determine the mode of a set of data.

Input

A sequence of lines. Each line will contain a non-negative integer no greater than 100 and represents one element of the data, except the last line, which contains the single integer -1 and is not part of the data.

Output

The mode of the set of data. If there is more than one mode, output all modes sorted in ascending order on separate lines.

Sample Input

2
3
4
4
-1

Sample Output

4

All Submissions
Best Solutions


Point Value: 4
Time Limit: 2.00s
Memory Limit: 16M
Added: Oct 23, 2008

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

i can find one mode, but i dont know how to find multiple modes,(note, im asking this for other questions as well). please help me

I ran my code on my computer (windows cmd) and it works fine but when I submit it says RE? Please take a look at my code and give me a hint on what went wrong?

The judge version of Python is 2.6.8, and you're trying to use collections.Counter, which was introduced in 2.7.

We may upgrade the version at some point, but for now you'll have to solve this another way. Apologies for the inconvenience.

Hi,
while programming I stumbled across on how to make the numbers equal the same amount of each other. If anybody could help me it would be much Appreciated.
THX
zainnaiz

You just do regular assignment. x = y, much as x = int(raw_input()).

If there is one of every number is every number the mode or does the question exclude this type of input?

I would not bother thinking about this extreme scenario: a good code should work for this problem no matter if there is one mode, ten modes or even the whole set is a mode.


Why am I exceeding the time limit.

your code simply is not fast enough neutral.gif
try approaching this problem in another way or finding optimizations

Because your code does not produce the correct answer fast enough, obviously.

If I may suggest, imho you are using one loop too many: you should be able to find the most common element in a single swoop, if your array is set in a particular configuration. Either that or you use another loop in a smarter way, that's your pick.

Btw, even if Python 3 here usually performs rather poorly, even compared to Python 2, know that it can be solved with it (I did) :)


what is the most amount of elements that will be entered

Longints will suffice.

If you have the right algorithm, you shouldn't have to worry about how many lines of input there can be.

Can someone tell me where i am going wrong in my program
i have read the announcement

... so if you've read the announcement, why are you not following its instructions?

Do you use multi dimensional arrays for this?

Just curious.

nope, you have to be smart about how you input.