题意:求出两点的距离。

解法:由于有一种情况相加将超出long long的最大表示范围,由于计算机将减法都视作是加法,因此溢出之后的值如果使用无符号格式控制符来输出的话,结果是对的。

代码如下:

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        long long int x, y, Max, Min;
        scanf("%lld %lld", &x, &y);
        Max = x > y ? x : y;
        Min = x < y ? x : y; 
        printf("%llu\n", Max - Min);
    }
    return 0;
}

 

相关文章:

  • 2021-11-20
  • 2021-10-31
  • 2022-02-05
  • 2021-11-25
  • 2021-09-11
  • 2021-12-26
  • 2021-08-22
  • 2022-12-23
猜你喜欢
  • 2021-07-23
  • 2021-09-28
  • 2021-12-22
  • 2021-06-20
  • 2021-09-16
  • 2021-06-22
  • 2021-08-11
相关资源
相似解决方案