UVa145 Gondwanaland Telecom,

Source: Internet
Author: User

UVa145 Gondwanaland Telecom,

Time limit: 3.000 seconds
Time Limit: 3.000 seconds

 

Problem
Problem

Gondwanaland Telecom makes charges for callaccording 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:
Gowana Telecom charges fees based on the time period and call distance during the day. The following table lists the Basic Call plans. The call phases are arranged by distance.

 

Charging Step
(Distance)
Day Rate
8 am to 6 pm
Evening Rate
6 pm to 10 pm
Night Rate
10 pm to 8 am
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. callwhich straddle a rate boundary are charged according to the time spent in each section. thus a call starting at pm and terminating at pm will be charged for 2 minutes at the day rate and for 4 minutes at the evening rate. callless than a minute are not recorded and no call may last more than 24 hours.
All calls are accrued in minutes. If a call spans two time periods, charges are collected based on the call time and rate during each time period. For example, if a call starts from to, the fee is calculated based on the two-minute daytime call rate and the four-minute evening call rate. The maximum number of calls is no more than 24 hours.

Write a program that reads call details and calculates the corresponding charges.
Write a program to read all the call information and calculate the corresponding phone fee.

 

Input and Output
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 #.
The input is composed of multiple rows, and each row of data includes the following data: Phone Call phase (uppercase letters: "A" to "E "), the number (a string consisting of a 7-Bit Array and a horizontal line), the start time and end time of the call. These data are separated by spaces. The time is represented by the hour and minute in the 24-hour format, separated by a space. Each number has two digits ). Only one single line of # indicates that the input is complete.

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.
Each output line includes the outgoing number, the number of minutes in each call phase, the number of the call phase, and the total cost. And output in the following format.

 

Sample Input
Input example

A 183-5724 17 58 18 04
#

 

Sample Output
Output example

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

The example output in the original text is a very unclear image. The above data comes from the output of my AC program. The format is exactly the same as that of the source image. The Gray Two-row header at the top represents the character position, which is for example reference only. Your program should not output this header. A red number indicates the position in which the data in the following column needs to be aligned (left aligned on the left and right aligned on the right ).

This question is very complicated at the beginning. There are two points to note: one is to be able to handle the problem that occurs at a.m., and the other is that if the start time and end time are equal, so let's talk for a day !!! (Because of this, I have never had AC, f ** k)


My code is as follows:

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.