ACdream 1061 (abs usage)
Mainly abs usage, reading question data
Maximum Value of long: 9223372036854775807
The minimum value of long:-9223372036854775808.
Maximum Value of unsigned long: 18446744073709551615
From the example of the question, we can see that the number range cannot exceed the long maximum value and can be output with unsigned long.
Question requirements:
It is said that Guo has planted another tree. He planted three trees A, B, and C along A straight road.
However, I forget the order of ABC from left to right. He only knows that B is on the right of.XSTEP (ifXIf it is negative, B is on the left side of.-XStep), C is on the right ofYSTEP (ifYFor C in the left side of-YStep ).
He wants to know how many steps BC is from (the answer must be positive and not 0 ).
Because he planted too many trees, he only knows| X |, | y |(Take the absolute value, | 1 | = 1, |-2 | = 2) ≤4611686018427387904
Input
The first row is the number of data groups.T (T ≤ 100000)
Two integers for each group of dataX, y (-4611686018427387904 ≤ x, y ≤ 4611686018427387904)
Output outputs a positive number for each group of data, indicating the distance between BC and Sample Input.
21 24611686018427387904 -4611686018427387904
Sample Output
1 9223372036854775808
The abs in our team has obtained the absolute value.
Tested and Baidu
However Abs in can't calculate the absolute value of long. Although fabs can pass the example, there may be errors, WA;
Abs and fabs are the same as those in cmath, but stdlib has llabs. You can calculate the absolute value of long.
Abs in can directly calculate the absolute value of long type, AC!
Test and AC code:
#include
//#include
//#include
#include using namespace std;typedef long long ll;ll x,y,z;int main(){int t;scanf(%d,&t);while(t--){scanf(%lld%lld,&x,&y);z=abs(y-x);//z=llabs(y-x);//z=fabs(y-x);printf(%llu,z);}return 0;}