This is a very simple problem! Your only job is to calculate a + b + c + d!
题目链接:https://ac.nowcoder.com/acm/contest/338/G
原文链接:https://blog.csdn.net/ordinarv/article/details/85932520
There are several cases.
In the first line, there is a single integer T.(T <= 200)
In the next T lines, each line contains four integers a, b, c and d(-2 ^ 61 <= a,b,c,d <=2 ^ 61)
2 ^ 61设坑精良,long long(8字节 * 每字节8位 - 1个符号位)到 2 ^ 63,假设a、b、c、d每个都是2 ^ 61,两个相加就是 2 ^ 62,三个相加就是 2 ^ 63,四个相加就是 2 ^ 64…long long溢出…然后就得用long double(12字节)
%.0f 会四舍五入,貌似根据.后第一位是否大于4判断。
floor函数 向下取整,即取不大于x的最大整数(与“四舍五入”不同,下取整是直接取按照数轴上最接近要求值的左边值,即不大于要求值的最大的那个值)。
long double 是用 %Lf 输出!
#include<bits/stdc++.h>
using namespace std;
long double a, b, c, d;
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
scanf("%Lf%Lf%Lf%Lf", &a, &b, &c, &d);
printf("%.0Lf\n", floor(a + b + c + d));
}
return 0;
}