数组内数字出现的次数

键盘输入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 <string>
using namespace std;
int main() {
    int x[10];
    for (int i=0;i<10;i++) {
        cin>>x[i];
    }

    for (int i=0;i<9;i++) {
        int count=1;
        for (int j=i+1;j<10;j++) { 
            if (x[i]==x[j]) count++;
        }
        cout<<x[i]<<" : "<<count<<" times"<<endl;
    }
}