#156. 判断三整数是否构成等差数列

    ID: 156 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatLogic-2gesp1条件结构数学基础

判断三整数是否构成等差数列

Evenly Spaced Integers

Background

Dawei is studying the properties of number sequences. He wants to know if three given integers can form an arithmetic progression.

Problem Description

Given three integers a,b,ca, b, c. One of them is small, one is medium, and one is large. Return true if the three values are evenly spaced, meaning the difference between the small and medium number is the same as the difference between the medium and large number. Otherwise, return false.

To determine if they are evenly spaced, you should first sort the three numbers. Let the sorted numbers be x,y,zx, y, z (such that xyzx \le y \le z). The condition to check is yx=zyy - x = z - y.

Input Format

Input is given from standard input in the following format.

Three integers a,b,ca, b, c.

Output Format

Output is printed to standard output in the following format.

Output true if the three numbers are evenly spaced; otherwise, output false.

Sample

2 4 6
true
4 6 2
true
4 6 3
false

Sample Explanation

Sample 1: The input is 2,4,62, 4, 6. Sorted, they are 2,4,62, 4, 6. The difference between the small and medium number is 42=24 - 2 = 2, and the difference between the medium and large number is 64=26 - 4 = 2. The two differences are equal, so true is output.

Sample 2: The input is 4,6,24, 6, 2. Sorted, they are 2,4,62, 4, 6. The difference between the small and medium number is 42=24 - 2 = 2, and the difference between the medium and large number is 64=26 - 4 = 2. The two differences are equal, so true is output.

Sample 3: The input is 4,6,34, 6, 3. Sorted, they are 3,4,63, 4, 6. The difference between the small and medium number is 43=14 - 3 = 1, and the difference between the medium and large number is 64=26 - 4 = 2. The two differences are not equal, so false is output.

Constraints

Time limit: 1s, Memory limit: 1024KiB for each test case.