题目链接:https://vjudge.net/problem/UVA-1225
题意:从1排到n,统计出现数字个数
题解:不要想复杂,直接取余加就可以---极限是1e9,1e10就不可以了,但对1000绰绰有余;用count反而更慢
ac代码
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n1,n;
cin>>n1;
while(n1--)
{
cin>>n;
int t[10]= {0};
for(int i=1; i<=n; i++)
{
int k=i;
while(k!=0)
{
t[k%10]++;
k/=10;
}
}
for(int i=0; i<10; i++)
{
if(i!=0)
cout<<‘ ‘;
cout<<t[i];
}
cout<<endl;
}
return 0;
}
原文:https://www.cnblogs.com/Joe2019/p/12668005.html