NOIP2007 Statistics
Time limit: 1 Sec memory limit: Ten MB the topic describes a scientific investigation when the N natural number is obtained, each number is not more than 1500000000 (1.5*109). There are no more than 10,000 known numbers, and it is now necessary to count the number of occurrences of these natural numbers, and to output the statistical results in the order of natural numbers from small to large. The first line of input is an integer n, which indicates the number of natural numbers;
Section 2~n+1 a natural number per line. The output contains m rows (m is the number of different numbers in N natural numbers), and is output in order from small to large in natural numbers. Each row outputs two integers, each of which is the natural number and the number of occurrences, separated by a space. Sample Input 8
2
4
2
4
5
100
2
Sample Output 2 3
4 2
5 1
2 hint 40% data to meet: 1<=n<=1000
80% of the data meet: 1<=n<=50000
100% data satisfies: 1<=n<=200000, each number is not more than 1500 000 000 (1.5*109)
var w:array[1..200000]of longint;
I,j:longint;
A,n,sum,ci:longint;
Procedure sort (l,r:longint);
var i,j,x,y,c:longint; Begin I:=l; J:=r;
x:=w[(l+r) Div 2];
Repeat while W[i]<x do Inc (i);
While X<w[j] do Dec (j); If not (I>J) then begin c:=w[i]; W[I]:=W[J];
W[j]:=c; Inc (I);
Dec (j);
End
Until i>j;
If L<j then sort (l,j);
If I<r then sort (i,r);
End
Begin READLN (n);
For I:=1 to N do readln (W[i]);
Sort (1,n);
Ci:=1;
While Ci<=n does begin sum:=0;
For J:=CI to n does begin if W[J]=W[CI] then Inc. (sum) else break;
End
Writeln (W[ci], ", sum);
Inc (Ci,sum);
End End.