ACdream 1061 (abs usage)

Source: Internet
Author: User

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;}
   
  
 


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.