答案

小黄  •  10小时前


include <bits/stdc++.h>

using namespace std;

int main() {

int cnt[10] = {0};  // 0~9出现次数,初始都是0
int n, x;
cin >> n;  // 输入数字个数

for (int i = 0; i < n; i++) {  // 循环n次,读入n个三位数
    cin >> x;

    // 拆出个位、十位、百位
    int a = x % 10;    // 个位
    int b = x / 10 % 10; // 十位
    int c = x / 100;   // 百位

    // 每个数字次数+1
    cnt[a]++;
    cnt[b]++;
    cnt[c]++;
}

// 输出 0~9 各自的次数
for (int i = 0; i < 10; i++) {
    cout << cnt[i] << endl;
}

return 0;

}


评论:

请先登录,才能进行评论