UVa – 1225 – Digit Counting

#include <iostream>
#include <string>
#include <string.h>
#include <sstream>
using namespace std;

int main() {
	int T, N, n[10];
	cin >> T;
	while (T-- && cin >> N) {
		stringstream s;
		while (N--) s << (N + 1);
		memset(n, 0, sizeof n);
		for (size_t c = 0; c < s.str().length(); c++)
			n[s.str()[c] - '0']++;
		for (int i = 0; i < 10; i++) {
			cout << n[i];
			if (i!=9) cout << " ";
		}
		cout << endl;
	}
	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

%d bloggers like this: