Uva oj 145-Gondwanaland Telecom)

Source: Internet
Author: User

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
evening rate
6 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 oneProgramRead all the call information and calculate the corresponding call charge.

 

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, For example reference only, your program does 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 ).

 

Analysis
Output example

There are a lot of solutions to a question without any difficulty, mainly to practice formatting output. You only need to pay attention to two points. One is to be able to calculate correctly when crossing 24 points (0 points), and the other is to be able to calculate 24 hours as required by the question, that is, the start time and end time are the same. For details about how to format data in C ++, seeCode.

 

Solution
Answer

# Include <iomanip> # include <iostream> # include <string> using namespace STD; // calculate the number of minutes in each time period based on the specified start time and start time. Void stepstatic (INT nbeg, int nend, int * pcate, int ncnt, int * presult) {int Ic = 0; // IC indicates the current time period. The following cycle finds the time period of the start time (; IC <ncnt-1 & nbeg> = pcate [IC]; ++ ic ); // The start time period minus the no call time before the start. presult [IC-1]-= (nbeg-pcate [IC-1]); // cyclically count the time of each time period for (-- IC; IC <ncnt-1 & nend> = pcate [IC]; ++ ic) {presult [IC] + = Pcate [IC + 1]-pcate [IC];} // The time range of the end time minus the end time without the call time presult [IC-1]-= (pcate [IC]-nend);} int main (void) {int Cate [] = {0, 8*60, 18*60, 22*60, 24*60}; // time period in minutes const int ncnt = sizeof (Cate) /sizeof (Cate [0]); // number of time periods int rate [5] [3] = {10, 6, 2}, {25, 15, 5 }, {53, 33, 13}, {87, 47, 17}, {144, 80, 30}; // Rate Table cout. SETF (ios_base: right); // The output format is right aligned. // the input data of each row is processed cyclically until the # sign is displayed. For (char cstep; CIN> CS TEP & cstep! = '#'; Cout <Endl) {string num; int begh, begm, endh, endm, ncharge = 0, result [ncnt-1] = {0 }; cin> num> begh> begm> endh> endm; // read data int nbeg = begh * 60 + begm, nend = endh * 60 + endm; if (nend <= nbeg) {// If the start time is less than or equal to the end time, // first count from the start time to 24, and then from 0 to the end time stepstatic (nbeg, cate [ncnt-1], Cate, ncnt, result); stepstatic (0, nend, Cate, ncnt, result );} else {// otherwise, the stepstatic (nbeg, nend, Cate, ncnt, result) from the start time to the end time is directly counted );} // combine the time period from the last to the 24: 00 and the time period starting from the 0: result [ncnt-2] + = Result [0]; cout <SETW (10) <num; // output phone number for (INT I = 1; I <ncnt-1; ++ I) {// when calculating the phone bill and outputting the calls for each period, ncharge + = Rate [cstep-'a'] [I-1] * result [I]; cout <SETW (6) <result [I] ;}cout <SETW (3) <cstep; // The output distance and total Phone Fee cout <SETW (8) <fixed <setprecision (2) <(ncharge/100366f);} 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.