sdnu1138shopping

来源:互联网 发布:无锡移动网络办理 编辑:程序博客网 时间:2024/06/05 05:36

1138.Shopping
Time Limit: 1000 MS    Memory Limit: 32768 KB
Total Submission(s): 91    Accepted Submission(s): 57
Description
Saya and Kudo 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<cstdio>#include<algorithm>using namespace std;#define r 100001int main(){    int j[r],a,b,i;    while(scanf("%d",&a)!=EOF&&a!=0)    {        b=0;        for(i=0;i<a;i++)        {            scanf("%d",&j[i]);        }        sort(j,j+a);        for(i=0;i<a-1;i++)        {            b+=j[i+1]-j[i];        }        b=b+j[i]-j[0];        printf("%d\n",b);    }    return 0;}