UVa145 Gondwanaland Telecom,

來源:互聯網
上載者:User

UVa145 Gondwanaland Telecom,

Time limit: 3.000 seconds
限時:3.000秒

 

Problem
問題

Gondwanaland Telecom makes charges for calls according to distance and time of day. The basis of the charging is contained in the following schedule, where the charging step is related to the distance:
岡瓦納電信公司按照一天中的時段和通話距離來收取話費。下表列出了基本通話費方案,其中話費階段是按距離遠近安排的。

 

Charging Step
(distance)
Day Rate
8am to 6pm
Evening Rate
6pm to 10pm
Night Rate
10pm to 8am
A 0.10 0.06 0.02
B 0.25 0.15 0.05
C 0.53 0.33 0.13
D 0.87 0.47 0.17
E 1.44 0.80 0.30

 

All charges are in dollars per minute of the call. Calls which straddle a rate boundary are charged according to the time spent in each section. Thus a call starting at 5:58 pm and terminating at 6:04 pm will be charged for 2 minutes at the day rate and for 4 minutes at the evening rate. Calls less than a minute are not recorded and no call may last more than 24 hours.
所有話費都是按照通話的分鐘數累計的。若一次通話跨越了兩個時段,則分別按照在各時段內的通話時間和費率進行收費。比如一次通話由晚5:58開始到晚6:04結束,則按2分鐘的白天通話和4分鐘的夜晚通話費率計算。通話少於1分鐘的不計費,最長的通話不會超過24小時。

Write a program that reads call details and calculates the corresponding charges.
寫一個程式讀取所有的通話資訊並計算對應的話費。

 

Input and Output
輸入與輸出

Input lines will consist of the charging step (upper case letter 'A'..'E'), the number called (a string of 7 digits and a hyphen in the approved format) and the start and end times of the call, all separated by exactly one blank. Times are recorded as hours and minutes in the 24 hour clock, separated by one blank and with two digits for each number. Input will be terminated by a line consisting of a single #.
輸入由多行組成,每一行資料都包括:話費階段(大寫字母“A”到“E”),撥出的號碼(一個7位元組和橫線組成的字串),通話的開始和結束時間。這些資料間都由空格隔開。時間均由24小時制的小時和分鐘錶示,之間由一個空格隔開,每個數字都有兩位元(譯註:不足兩位的前面補零)。只有一個#號的單獨一行表示輸入結束。

Output will consist of the called number, the time in minutes the call spent in each of the charge categories, the charging step and the total cost in the format shown below.
輸出的每一行要包括撥出的號碼,每一個話費階段的分鐘數,話費階段編號以及總費用。並按如下格式輸出。

 

Sample Input
輸入樣本

A 183-5724 17 58 18 04
#

 

Sample Output
輸出樣本

0         10        20        30
123456789012345678901234567890123456789
  183-5724     2     4     0  A    0.44

譯註:原文中的樣本輸出為一張很不清晰的圖片。上面的資料來自我AC的程式輸出,格式與原圖完全相同。最上麵灰色的兩行為表頭表示字元的位置,只作樣本參照,你的程式不要輸出該表頭。紅色的數字表示下面一列資料需要對齊的位置(在下面一列的左側為靠左對齊,在右側為靠右對齊)。

這題一開始想的非常複雜,這題有兩個注意點,一是要能夠處理跨淩晨0點的問題,二是如果開始時間和結束時間相等的話,那麼算通話一天!!!(就是因為這一點,我一直沒AC,f**k)


My Code如下:

#include<iostream>#include<stdio.h>typedef struct price{    char step;    double a;    double b;    double c;}price;price s[5]={    {'A',0.10,0.06,0.02 },    {'B',0.25,0.15,0.05},    {'C',0.53,0.33,0.13},    {'D',0.87,0.47,0.17},    {'E',1.44,0.80,0.30}};char phone_number[8];char tt;int sh,sm,eh,em;int startindex;int endindex;int a,b,c;inline double getprice(int i,int index){    //printf(" %d\n",i);    if(i<=480){c++;return s[index].c;}    if(480<i&&i<=1080){a++;return s[index].a;}    if(1080<i&&i<=1320){b++;return s[index].b;}    if(i>1320){c++;return s[index].c;}}int main(int argc, char *argv[]){    //freopen("1.in","r",stdin);    scanf("%c",&tt);    while(tt!='#'){        char cc=tt;        scanf("%s",phone_number);        scanf("%d %d %d %d",&sh,&sm,&eh,&em);        a=b=c=0;        int index=0;        for(;index<5;++index)        {            if(s[index].step==cc)                break;        }        int E=eh*60+em;        int S=sh*60+sm;        double sum=0;        if(S<E){            for(int i=S+1;i<=E;++i)            {                sum+=getprice(i,index);            }        }        else if(S==E)        {            for(int i=S+1;i<=1440;++i)                sum+=getprice(i,index);            for(int i=1;i<=E;++i)                sum+=getprice(i,index);        }        else        {            for(int i=S+1;i<=1440;++i)                sum+=getprice(i,index);            for(int i=1;i<=E;++i)                sum+=getprice(i,index);        }        printf("%10s%6d%6d%6d%3c%8.2lf\n", phone_number, a, b,c, cc, sum);        scanf("\n%c",&tt);    }    return 0;}


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.