谁能帮我翻译并解答Speed Limit这道ACM题啊!

来源:百度知道 编辑:UC知道 时间:2024/06/21 20:36:37
谁能帮我完整的翻译一下所有的英文,还有就是解答一下这道题,要有解题思路和主要使用的算法,最重要的是在源程序上加上注释好让我理解,我是菜鸟~~哪位高手帮帮忙~~~~先谢谢了~~~

题目: Speed Limit
Description

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 perhour 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 dri

我的AC的代码
#include<stdio.h>

int main(void)
{
int n=0;
int i=0;
int data[11][2]={0,0};
int miles=0;

//freopen("t.txt","r",stdin);
while(1)
{
scanf("%d",&n);
if(n==-1)
return 0;
miles=0;
for(i=1;i<=n;i++)
{
scanf("%d %d",&data[i][0],&data[i][1]);
miles+=data[i][0]*(data[i][1]-data[i-1][1]);
}
printf("%d miles\n",miles);
}
return 0;
}

题目意思就是计算走了多少路程
第一个数字表示速度
第二个数字表示时间
时间是叠加的

翻译:
输入包括一组或多组数据
每组数据由一个数字n开始 n占一行 1<=n<=10
接下来的n对数字每对一行
第一个数字s 表示速度 英里每小时
第二个数字t 表示时间 小时
1<=s<=90 and 1<=t<=12
t的值严格递增
-1表示结尾

每组输入对应输出路程
空格
miles

3
20 2
30 6
10 7

第1-2小时速度为20
第3-6小时速度为30
第7小时速度为10
加起来就行
20*2+30*4+10*1=170