程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> UVa145 Gondwanaland Telecom

UVa145 Gondwanaland Telecom

編輯:C++入門知識

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)


我的代碼如下:

#include
#include
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(4801320){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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved