UVa : 1225 (Digit Counting)



// http://uva.onlinejudge.org/external/12/1225.html
// runtime: 0.012s
// tag: adhoc, frequency


#include <cstdio>
#include <cstring>

using namespace std;

int main ()
{
    int testCase; scanf ("%d", &testCase);

    while ( testCase-- ) {
        int n; scanf ("%d", &n);
        int cnt [10];

        memset (cnt, 0, sizeof cnt);

        for ( int i = 1; i <= n; i++ ) {
            int tmp = i;
            while ( tmp ) {
                cnt [tmp % 10]++;
                tmp /= 10;
            }
        }

        for ( int i = 0; i < 9; i++ ) printf ("%d ", cnt [i]);
        printf ("%d\n", cnt [9]);
    }

    return 0;

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s