作业帮 > 综合 > 作业

ACM 题目 求高人解答 (C C++)

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/29 00:47:15
ACM 题目 求高人解答 (C C++)
Problem Description
JJ and WW go shopping together. You can assume the street as a straight line, while the shops are some points on the line. They park their car at the leftmost shop, visit all the shops from left to right, and go back to their car. Your task is to calculate the length of their route.

Input
The input consists of several test cases. The first line of input in each test case contains one integer N (0
///题目中说车停在最左边的商店,然后又要把所有的商店走完,并回来
///问的是最短距离,很显然是直接从左边走到右边再回来,那当然是取商店座标的最大
///值和最小值减一下乘以后就是答案了
#include
#include
int main()
{
int n;
int max_,min_;
int p;
while(scanf("%d",&n)!=EOF&&n>0)
{
n--;
scanf("%d",&max_);
min_=max_;
while(n--)
{
scanf("%d",&p);
if(pmax_)
{
max_=p;
}
}
printf("%d\n",(max_-min_)*2);
}
return 0;
}