输出从1到n中,0123456789各个数字出现次数
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cmath>
using namespace std;
int main()
{
int n;
cin >> n;
int l;
int p[10] = {0,0,0,0,0,0,0,0,0,0};
for (int i = 1; i <= n; i++)
{
l = i;
while(l>0)
{
int m;
m = l % 10;
l = l / 10;
// cout << m << " ";
p[m] += 1;
}
// cout << endl;
}
for (int j = 0; j < 10; j++)
{
cout << p[j] << endl;
}
return 0;
}