您的位置:首页 > 其它

AcDream 1079 郭氏数

2013-03-19 17:14 239 查看
题意:求出两点的距离。

解法:由于有一种情况相加将超出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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: