POJ 2017 Speed Limit C++版

题目链接:http://poj.org/problem?id=2017

给出每段时间的速度,求出长度,分段计算就是了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/***************************************
Problem: 2017 User: awq123
Memory: 248K Time: 0MS
Language: C++ Result: Accepted
***************************************/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
int n,i,d[11][2],sum;
while(cin>>n&&n;!=-1)
{
d[0][1]=0;
sum=0;
for(i=1;i<=n;i++)
{
cin>>d[i][0]>>d[i][1];
sum+=d[i][0]*(d[i][1]-d[i-1][1]);
}
cout<<sum<<" miles"<<endl;

}

}