Photolog

Through the Looking-Glass
2010-10-12: Through the Looking-Glass
My radio speaks is binary!
2010-10-10: My radio speaks is binary!
Gigaminx: (present for my birthday)
2010-09-16: Gigaminx: (present for my birthday)
Trini on bike
2010-09-05: Trini on bike
Valporquero
2010-08-28: Valporquero
My new bike!
2010-08-22: My new bike!
Mario and Ana's wedding
2010-08-13: Mario and Ana's wedding
Canyoning in Guara
2010-08-07: Canyoning in Guara
Trini and Mari in Marbella
2010-08-05: Trini and Mari in Marbella
Trini and Chelo in Tabarca
2010-08-03: Trini and Chelo in Tabarca
Valid XHTML 1.1
Log in
Back to list of problems

Roman Digititis

344.c

#include <stdio.h>

int
num_i(int n) {
	int a = n%5;

	if (a == 4) {
		return 1;
	} else {
		return a;
	}
}

int
num_v(int n) {
	n %= 10;

	if (n>=4 && n<=8) {
		return 1;
	} else {
		return 0;
	}
}

int
num_x(int n) {
	n %= 50;

	if (n<=8) {
		return 0;
	} else if (n>=9 && n<=18) {
		return 1;
	} else if (n>=19 && n<=28) {
		return 2;
	} else if (n>=29 && n<=38) {
		return 3;
	} else if (n==39) {
		return 4;
	} else if (n>=40 && n<=48) {
		return 1;
	} else { /* 49 */
		return 2;
	}
}

int
num_l(int n) {
	if (n>=40 && n<=89) {
		return 1;
	} else {
		return 0;
	}
}

int
num_c(int n) {
	if (n>=90) {
		return 1;
	} else {
		return 0;
	}
}

int
main(void) {
	int n;
	int a;
	while (1) {
		int i=0,v=0,x=0,l=0,c=0;
		scanf("%d", &n);
		if (n==0) {
			return 0;
		}
		for (a=1; a<=n; a++) {
			i += num_i(a);
			v += num_v(a);
			x += num_x(a);
			l += num_l(a);
			c += num_c(a);
		}
		printf("%d: %d i, %d v, %d x, %d l, %d c\n", n, i, v, x, l, c);
	}
}