uva 1225 Digit Counting

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int change(char ch)
{
    return ch-'0';
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        char ch[10005];
        int a[10];
        memset(a,0,sizeof(a));
        for(int i=1;i<=n;i++)
        {
            sprintf(ch,"%d",i);
            for(int i=0;i<(int)strlen(ch);i++)
                a[change(ch[i])]++;
        }
        for(int i=0;i<10;i++)
        {
            if(i==0) cout<<a[i];
            else cout<<" "<<a[i];
        }
        cout<<endl;
    }
    return 0;
}

你可能感兴趣的:(uva 1225 Digit Counting)