关于long long 的问题
在HIT 上做了一个题,题目如下:
For each pair of integers A B and C ( -2^31 <= A, B, C<= 2^31-1 ), Output the result of A+B+C on a single line.
Sample Input
1 2 3
3 4 3
Sample Output
6
10
提示 请注意32位机上int的表示范围。
提交代码的时候,使用了long long,代码如下
这样就一直都是WA,后来改成如下:
就成功AC了!
第一次用long long,不太了解。希望有高手来解答一下。
For each pair of integers A B and C ( -2^31 <= A, B, C<= 2^31-1 ), Output the result of A+B+C on a single line.
Sample Input
1 2 3
3 4 3
Sample Output
6
10
提示 请注意32位机上int的表示范围。
提交代码的时候,使用了long long,代码如下
#include <iostream>
using namespace std;
int main()
{
long long a,b,c;
while(cin>>a>>b>>c)
{
cout<<a+b+c<<endl;
}
return(0);
}这样就一直都是WA,后来改成如下:
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
while(cin>>a>>b>>c)
{
long long d = 0;
d += a;
d += b;
d += c;
cout<<d<<endl;
}
return(0);
}就成功AC了!
第一次用long long,不太了解。希望有高手来解答一下。
...全文
相关推荐
Java编程long数据类型的使用问题
long 数据类型的使用问题在 Java 编程中,long 数据类型经常用于表示大整数值,例如时间戳、身份证号码等。在使用 long 数据类型时,需要注意以下问题:* 在计算时,需要注意溢出问题。
SpringBoot全局配置long转String丢失精度问题解决方案
无论采用哪种方式,都能有效地避免前端接收到的Long数据出现精度问题,确保数据的完整性和准确性。
解决Intellij IDEA运行报Command line is too long的问题
解决Intellij IDEA运行报Command line is too long的问题问题背景在使用Intellij IDEA开发时,经常会遇到"Command line is too long"的错误信息
c代码-1.4类型转换 int,short,long,long long都是整型,整型都用%d来接收?还没解决这个问题
标题和描述中提到的问题集中在整型数据类型上,包括int, short, long以及long long。这些类型都是用于存储整数值,但它们各自有不同的大小和范围。
Long类型精度丢失问题[代码]
为了解决这个问题,开发人员采取了一种策略,即将后端传递的Long类型参数转换为String类型。


