2010年9月17日 星期五

ACM 145 - Gondwanaland Telecom

#include <stdio.h>
#include <stdlib.h>
struct Converse
{
char charge, telephone[8];
int sHour, sMin, eHour, eMin;
};
void getTime (int sH, int sM, int eH, int eM);
struct Converse c;
float charging[5][3] = { {0.10, 0.06, 0.02},
{0.25, 0.15, 0.05},
{0.53, 0.33, 0.13},
{0.87, 0.47, 0.17},
{1.44, 0.80, 0.30} };
int dayTime, eveningTime, nightTime;
int main()
{
while (1)
{
scanf("%c",&c.charge);
if (c.charge == '#') break;
scanf("%s %d %d %d %d",c.telephone ,&c.sHour ,&c.sMin ,&c.eHour ,&c.eMin);
int chargeIndex = c.charge - 'A';
dayTime = 0, eveningTime = 0, nightTime = 0;

if(c.sHour >= c.eHour && c.sMin >= c.eMin)
getTime(c.sHour, c.sMin, 24, 0) ,getTime(0, 0, c.eHour, c.eMin);
else
getTime(c.sHour, c.sMin, c.eHour, c.eMin);

float money = (float)(dayTime * charging[chargeIndex][0]) +
(float)(eveningTime*charging[chargeIndex][1]) +
(float)(nightTime*charging[chargeIndex][2]);

printf("%10s%6d%6d%6d%3c%8.2f\n", c.telephone, dayTime, eveningTime, nightTime, c.charge, money);
char ch = getchar();
}
return 0;
}

void getTime (int sH, int sM, int eH, int eM)
{
if (sH < 8)
{
if (eH >= 8) nightTime += (8 - sH) * 60 - sM, sH = 8, sM = 0;
else nightTime += (eH - sH) * 60 + eM - sM;
}
if (eH >= 8 && sH <= 18)
{
if (eH >= 18) dayTime += (18 - sH) * 60 - sM, sH = 18, sM = 0;
else dayTime += (eH - sH) * 60 + eM - sM;
}
if (eH >= 18 && sH < 22)
{
if (eH >= 22) eveningTime += (22 - sH) * 60 - sM, sH = 22, sM = 0;
else eveningTime += (eH - sH) * 60 + eM - sM;
}
if (eH >= 22)
nightTime += (eH - sH) * 60 + eM - sM;
}

回目錄
回首頁

沒有留言 :

張貼留言

Related Posts Plugin for WordPress, Blogger...