大数加

赵子龙的 abcd

description 
今天,赵子龙在愉快地刷题时,碰到了这样一道题: 
给出非负正数a,b,c,d,求a+b+c+d; 
赵子龙:????这么简单???? 
现在,就请你帮组赵子龙刷掉这道简单题吧。 
input 
第一行,测试数组组数T(T<100) 
对于每一组数据,都有四个非负正数a,b,c,d(0<=a,b,c,d<=2^62) 
output 
a+b+c+d的值 
simple input 

0 0 0 0 
1 1 1 1 
simple output 

4

当a,b,c,d都为 2^62次方时,ans才为2^64,这时可a=b=c=d=2^62,输出2^64对应的字符串;对于其他情况,unsigned long long 就可操作; 
当然,用大整数是肯定可以的。

#include "bits/stdc++.h"
using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        unsigned long long a,b,c,d;
        cin >> a >>b >> c >> d;
        unsigned long long x=4611686018427387904;
        if(a==x&&b==x&&c==x&&d==x)
        {
            cout<<"18446744073709551616"<<endl;
        } else
            cout << a+b+c+d <<endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/cunyusup/p/8260891.html