Program | MAJ.C, MAJ.CPP, MAJ.PAS |
The majority number of a non-empty sequence of N numbers is precisely that number which occurs more than N/2 times in the sequence. Therefore, for a non empty sequence, there is at most one such number. For example, the sequence 3, 3, 4, 2, 4, 4, 2, 4, 4 has the majority number 4, whereas the sequence 3, 3, 4, 2, 4, 4, 2, 4 has no majority number.
The text file contains non empty sequences of integers x (-200000000 < x
< 200000000). Each sequence, which can be pretty long, starts with a number
that specifies the number of long integers in the sequence. This number is not
part of the sequence. The numbers are separated freely by white-spaces (spaces,
tabs and line-breaks). The data in the text file are guaranteed correct.
Write a program that for each sequence of integers read from the text file outputs
the majority number of the sequence. If there is no such number the message
No majority number
is printed. The results are printed on separate
lines. The end of data is marked by sequence with 0 elements. There is no output
for this sequence.
Sample MAJ.IN
6
100000 -2 56 100000 -2
56
5
-2 100 -2 -2 1001
1
1000
0
MAJ.OUT
No majority number
-2
1000