键盘输入10个整数,统计每个数出现的次数
如:8 2 3 2 5 6 8 2 0 5
则:
8:出现了2次
2:出现了3次
3:出现了1次
5:出现了2次
6:出现了1次
0:出现了1次
Input
输入10个整数
Output
输出每个数出现的次数,顺序以每个数出现的先后次序为准
Sample Input
8 2 3 2 5 6 8 2 0 5
Sample Output
8:2 2:3 3:1 5:2 6:1 0:1
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int a[11],i,b[11],c[11]={0};
for(i=1;i<=10;i++)
{
cin>>a[i];
b[a[i]]=i;
c[a[i]]++;
}
sort(b,b+10);
for(i=1;i<=9;i++)
{
cout<<a[i]<<':'<<c[a[i]]<<' ';
}
cout<<endl;
return 0;
}
有一部分还需完善