首页 > Code > calculating the taxi fares

calculating the taxi fares

2007年8月14日 发表评论 阅读评论 707 views

The rules for calculating the taxi fares are quite complex. Many factors are to be considered in computing the taxi fares, including the length of the trip, the time of the day, the speed, etc. Every morning Bianca Bennett uses taxi to get to her office, she thinks if taximeters are programmed correctly. One day, she decided to write a program to calculate the taxi fares to check this.

Imagine a taxi passes through a sequence of streets S1, S2, …, Sn in order. The length of Si is Li and it is assumed that the taxi travels in a constant speed and it takes Mi minutes to travel one kilometer in Si. To make it simple, assume the passenger gets in at the start of a street Si and gets out at the end of the destination street Sj (i.e., he does not get in or out in the middle of a street). The passenger is charged for each kilometer of the trip. The first ten kilometers of the trip cost 1000 Rials each. The next 20 kilometers (from 11 to 30) cost 250 Rials each. After that, each kilometer costs 100 Rials

During the night, the fare is increased by 20%. The rule is that for each kilometer, if the taxi travels at least one minute during the time interval [12 AM, 6 AM], that kilometer will cost 20% more. Since driving in a heavy traffic costs more, if the average speed of the taxi is less than 30 km/h during the whole trip, the fare is increased by 10%.

The input consists of multiple test cases. The first part of each test case is the sequence of streets the taxi travels. This comes in several lines, each describing one street in the form of street-name length min. street-name is a unique string of at most 20 letters and digits with no blank in it, and length and min are two positive integer numbers which are Li; (measured in kilometers, at most 200) and Mi (measured in minutes) respectively. Each street is visited once by the taxi. The first part of the test case is terminated by a line containing a single $ character. The second part of the test case contains a single line of the form source-street dest-street time. The first two items are the names of the source and the destination streets respectively. The third item is the time the passenger gets in which is in standard 24-hours format (HH:MM). There is a line containing a single # character at the end of each test case. You may assume that the source and the destination streets belong to the input sequence of streets and the destination street does not come before the source street. The last line of the input contains two dash characters as shown in the sample input.

出租车费用的计算程序是相当复杂的。计算出租车费用,许多因素要被考虑,包括旅程长度,一天里面的时间段,速度等等。每天早晨Bianca Bennett打的到她的办公室,她在考虑车费指示器的程序是否正确。一天,她决定写一段程序来计算出租车费来检验一下。

假设一辆出租车驶过一系列有先后顺序的街道S1,S2,…Sn。Si的长度是Li,假设出租车以匀速驶过,并且在Si中每行驶一公里要花费Mi分钟。打个比方,假设乘客在Si的端点处上车,并在街道Sj的末端下车(中途并没有逗留)。该乘客为这次trip付钱。第一个10公里为每公里1000里亚尔(伊朗的银币)。接下来的20公里(即从11到30)为每公里250里亚尔。再接下来就以每公里100里亚尔计费。

在夜间,费用增加了20%。计费规则是如果该出租车在6AM到12AM这个时间段内行驶超过一分钟,那每公里要涨价20%。因为在交通拥挤时行驶要花费更多,如果全程的平均速度低于30km/h,费用将增加10%。

输入部分由多重检测条件组成。每一项检测条件的第一部分是出租车行驶过的街道的序列。这要分成数行,每一行以“街道名称 长度 行驶时间”这一格式来描述。街道名称是一段包含最多20个字母和数字并无空格的唯一字符串,长度和行驶时间是两个正整数,分别是Li(按公里计算,最大200)和Mi(以分钟计算)。每一条街道被出租车访问一次。检测条件的第一部分以一行包含$的字符结束。检测条件的第二部分只包含一行,格式为“起点街道 终点街道 时间”。前两个元素分别是起点街道和终点街道的名称,第三个元素是乘客上车的时间,为标准的24小时制格式。每一项检测条件的最后都以包含一个$字符的一行作为中止符号。你可以假设起点街道和中止街道属于输入的序列街道,并且中止街道不能在起点街道前面。输入的最后一行包含与输入例中一样的两个破折号。

分类: Code 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.

:wink: :twisted: :roll: :oops: :mrgreen: :lol: :idea: :evil: :cry: :cool: :arrow: :?: :-| :-x :-o :-P :-D :-? :) :( :!: 8-O