Acdream 1061 (ABS usage)

Source: Internet
Author: User
Tags cmath

Title Link: http://acdream.info/problem?pid=1061

Mainly ABS usage, see the data of the topic

The maximum value of long long: 9223372036854775807
The minimum value of long long:-9223372036854775808
Unsigned the maximum value of long long: 18446744073709551615

By the example of the problem, it can be seen that the range of numbers does not exceed the long long maximum value with the unsigned long long output.


Title Requirements:

Legend has it that Guo camels from again planted trees, he along a straight road planted 3 tree a,b,c.

But forgetting ABC's left-to-right order, he only knows that B is x -Step (if x is negative, B is at the left-X step of a), and C is at y -Step (if y To be responsible for C at the left of a- y Step).

He wants to know how many steps BC is away (the answer must be positive and not 0).

Because he planted too many trees, he only knew |x|, |y| (Take absolute value, |1| = 1, |-2| = 2) ≤ 4611686018427387904

Input

The first line is the number of data groups T (t≤100000)

Two integers x, y ( -4611686018427387904≤x, y≤4611686018427387904) per group of data

Output a positive number for each set of data represents the distance between BC sample Input
21 24611686018427387904-4611686018427387904
Sample Output
1 9223372036854775808

Our team used ABS in <algorithm> to find out the absolute value.

After testing and Baidu

However, ABS in <cmath> can not find the absolute value of long long, although fabs may be an example, but there might be an error bar, WA;

ABS and Fabs in <cstdlib> are the same as in Cmath, but there are llabs in Stdlib, the absolute value of long long can be obtained, AC

ABS in <algorithm> can be directly obtained by the absolute value of long long type, ac!

Test and AC code:

#include <stdio.h>//#include <cmath>//#include <cstdlib> #include <algorithm>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);p rintf ("%llu\n", z);} return 0;}


Acdream 1061 (ABS usage)

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.