周睿 • 11天前
using namespace std;
int main() {
int n;
cin >> n; // 读取数字的数量
int count[10] = {0}; // 用于统计0-9每个数字出现的次数
for (int i = 0; i < n; i++) {
int num;
cin >> num; // 读取一个三位数
// 分解出百位、十位和个位数字
int hundreds = num / 100;
int tens = (num / 10) % 10;
int units = num % 10;
// 对应数字的计数加1
count[hundreds]++;
count[tens]++;
count[units]++;
}
// 输出统计结果,0-9每个数字一行
for (int i = 0; i < 10; i++) {
cout << count[i] << endl;
}
return 0;
}
评论:
请先登录,才能进行评论