题目描述
某次科研调查时得到了 n 个自然数, 每个数均不超过 1500000000(1.5*109). 已知不相同的数不超过 10000 个, 现在需要统计这些自然数各自出现的次数, 并按照自然数从小到大的顺序输出统计结果.
程序输入说明
- 8
- 2
- 4
- 2
- 4
- 5
- 100
- 2
- 100
- 2 3 4 2 5 1 100 2
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- #include<cstring>
- using namespace std;
- int count = 0;
- int b[10005],c[10005];
- int main(){
- int n;
- cin>>n;
- int a[n];
- for( int i = 0; i <n; i++ )
- cin>>a[i];
- sort(a,a+n);
- int j = 0,k = 0;
- for( int i = 0; i < n; i++ ){
- if( a[i] == a[i+1] )
- b[j]++;
- if( a[i] != a[i+1] ){
- c[k++] = a[i];
- j++;
- }
- }
- for( int i = 0; i < k; i++ ){
- cout<<c[i]<<" "<<b[i]+1<<endl;
- }
- return 0;
- }
来源: http://www.bubuko.com/infodetail-2891646.html