這題只要想得出方法來算個時段的分鐘數,就可以解得出來了,跨夜時段比較難算,其他大概就沒有甚麼問題了。
以下是主程式程式碼:
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;
}
接下來 getTime 函式就交給大家去寫了。
By David.K
p145題目連結
回ACM題庫目錄
回首頁
沒有留言:
張貼留言