Zoj problem set-2176 Speed Limit

Source: Internet
Author: User

Time Limit: 2 seconds memory limit: 65536 KB

Bill and Ted are taking a road trip. but the odometer in their car is broken, so they don't know how many miles they have driven. fortunately, Bill has a working stopwatch, so they can record their speed and the total time they have driven. unfortunately, their record keeping Strategy is a little odd, so they need help computing the total distance driven. you are to write a program to do this computation.

For example, if their log shows

Speed in miles per hour
Total elapsed time in hours

20
2

30
6

10
7

This means they drove 2 hours at 20 miles per hour, then 6-2 = 4 hours at 30 miles per hour, then 7-6 = 1 hour at 10 miles per hour. the distance driven is then (2) (20) + (4) (30) + (1) (10) = 40 + 120 + 10 = 170 miles. note that the total elapsed time is always since the beginning of the trip, not since the previous entry in their log.

Input

The input consists of one or more data sets. Each set starts with a line containing an integerN, 1 ≤ n ≤ 10, followedNPairs of values, one pair per line. the first value in a pair, S, is the speed in miles per hour and the second value, T, is the total elapsed time. both S and T are integers, 1 ≤ S ≤ 90 and 1 ≤ T ≤ 12. the values for t are always in strictly increasing order. A value of-1 for N signals the end of the input.

Output

For each input set, print the distance driven, followed by a space, followed by the word "Miles ".

Example input:
Example output:

3
20 2
30 6
10 7
2
60 1
30 5
4
15 1
25 2
30 3
10 5
-1
170 miles
180 miles
90 miles

Source:Mid-Central USA 2004

 
1: # include <iostream>
 
2:Using NamespaceSTD;
3:
 
4:IntMain ()
 
5 :{
 
6:IntN;
 
7:While(CIN> N & n! =-1)
8 :{
 
9:IntS, T, Pret = 0, distance = 0;
 
10:While(N -- & CIN> S> T)
 
11 :{
 
12: distance + = (t-pret) * s;
13: pret = T;
 
14 :}
 
15: cout <distance <"Miles"<Endl;
 
16 :}
 
17:Return0;
 18 :}

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.