4998: a+b+c+d=?
Description
This is a very simple problem! Your only job is to calculate a + b + c + d!
Input
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)
Output
output T lines.
Each line output one integer represent the answer of a + b + c + d
Sample Input
1
1 2 3 4
Sample Output
10
思路
实际上很简单,就是将四个数加起来就行了
a+b+c+d,并用repeat来决定需要输入的数据组数
细节
很多人再交上去的时候都会出现过不了的情况,为什么呢?
大家需要注意的是a,b,c,d的取值范围是(-2^61 <= a,b,c,d <=2^61)
有些人会说那我把它们都定义为long long不就够了吗
long long最大不就是 2^63 嘛,刚好四个数4 * 2^61= 2^63
但值得注意的是, 2^63是恰好取不到的数,所以我们应该用一个更大的类型来定义,这里给大家介绍一个long double它比long long还要长
long long是占了8个字节而long double占了12个字节
long double是用 %Lf 进行输出
展示代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
long double a,b,c,d,sum;
int repeat,t;
while(scanf("%d",&repeat)!=EOF) //持续输入
{
for(t=0;t<repeat;t++)
{
scanf("%Lf%Lf%Lf%Lf",&a,&b,&c,&d);
sum=a+b+c+d;
printf("%.0Lf\n",sum); //保留0位小数
}
}
return 0;
}
结尾
希望对大家有帮助!!!
有问题可在下面留言,谢谢…
哈哈,还是一样…
本人刚开始学没多久,并且心理承受能力不太行,如有错误或更好的方法请好好说,千万别骂我,拜托拜托😅🙏