[Tough problem] A mode is the number in a sequence that appears the most number of times.
A user is prompted to enter a sequence of non-negative numbers in non-decreasing
order one-by-one. The user indicates the end of the sequence by entering a
negative number. Write a script to obtain such user input and determine the
mode of the sequence.
If there are multiple
modes, you may report any one of them as the mode. Do not use arrays.
Below is an example run:
Determine mode of a set of nonnegative integers.
Use a negative number to quit.
Give me a number: 70
Another number not smaller than the previous: 71
Another number not smaller than the previous: 80
Another number not smaller than the previous: 80
Another number not smaller than the previous: 80
Another number not smaller than the previous: 91
Another number not smaller than the previous: 93
Another number not smaller than the previous: -1
Mode is 80.