您的位置:首页 > 其它

Codeforces 723A-The New Year: Meeting Friends

2016-11-15 15:21 3479 查看
A. The New Year: Meeting Friends

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x1,
the second friend lives at the point x2,
and the third friend lives at the point x3.
They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?

It's guaranteed that the optimal answer is always integer.

Input

The first line of the input contains three distinct integers x1, x2 and x3 (1 ≤ x1, x2, x3 ≤ 100) —
the coordinates of the houses of the first, the second and the third friends respectively.

Output

Print one integer — the minimum total distance the friends need to travel in order to meet together.

Examples

input
7 1 4


output
6


input
30 20 10


output
20


Note

In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from
the point 7 to the point 4), the second friend also has to
travel the distance of 3 (from the point 1 to the point 4),
while the third friend should not go anywhere because he lives at the point 4.

题意:
找出与其相隔距离和最小的那个点。
解:
排序之后找出中间那个数就是。
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

int main()
{

int a[3];
while(~scanf("%d%d%d",&a[0],&a[1],&a[2]))
{
int sum=0;
sort(a,a+3);
for(int i=0;i<2;i++)
sum+=a[i+1]-a[i];
printf("%d\n",sum);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息