USACO 2.2.1 – Preface Numbering

#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
char s[10]=" IVXLCDM";
int n, c[10] = {0} ,delta[10][5] = {{},{-1,-10},{-1,-1,-10},{-1,-1,-1,-10},{0,-1,-10}, {0, -10},{0,-1,-10},{0,-1,-1,-10},{0,-1,-1,-1,-10},{1,-1,-10} };

int main() {
	freopen("preface.in", "r", stdin), freopen("preface.out", "w", stdout);
	scanf("%d", &n);
	for(int p=1; p<=n; p++)
		for(int e=1; e<=4; e++){
			int d = int(p/(round(pow(10, e-1))))%10;
			if(!d) continue;
			for(int i=0; delta[d][i]!=-10; i++)
				c[2*e +delta[d][i]]++;
		}
	for(int i=1; i<=7 && c[i]; i++)
		cout << s[i] << " " << c[i]<<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: