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; }