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

Gondwanaland Telecom

145.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int array[5][3] = {
/*   8-18 18-20 20-8 */
	{  10,   6,   2},
	{  25,  15,   5},
	{  53,  33,  13},
	{  87,  47,  17},
	{ 144,  80,  30},
};

void
doit(char step, char * number, int beghour, int begmin, int endhour, int endmin) {
	int begin, end;
	int a=0, b=0, c=0;
	int i;
	int sum = 0;

	begin = beghour * 60 + begmin;
	end = endhour * 60 + endmin;

	if (end <= begin) {
		end += 24*60;
	}
	for (i=0; i<48*60; i++) {
		if (begin <= i && i < end) {
			if (i%(24*60) < 8*60) {
				c++;
			} else if (i%(24*60) < 18*60) {
				a++;
			} else if (i%(24*60) < 22*60) {
				b++;
			} else {
				c++;
			}
		}
	}
	sum = a*array[step-'A'][0] + b*array[step-'A'][1] + c*array[step-'A'][2];
	printf("%10s %5d %5d %5d  %c %4d.%02d\n", number, a, b, c, step, sum/100, sum%100);
}

int
main(void) {
	char step[100], number[100];
	int beghour, begmin, endhour, endmin;

	while (1) {
		if (scanf(" %s %s %d %d %d %d", step, number, &beghour, &begmin, &endhour, &endmin) != 6) {
			break;
		}
		if (step[0]=='#') {
			break;
		}
		doit(step[0], number, beghour, begmin, endhour, endmin);
	}
	return 0;
}