题解:P17073 [ICPC 2017 Shenyang R] Little Boxes

· · 题解

题解:P17073 [ICPC 2017 Shenyang R] Little Boxes

签到题

每次输入四个数 a,b,c,d ,求 a+b+c+d 的值 。

因为 a,b,c,d\le2^{62} ,所以可以直接用long long读入。

然后相加的时候使用__int128存放答案,由于__int128不能直接输出,所以可以手写一个输出函数。

void print(__int128 x){
    if(x==0){
        cout<<0<<"\n";
        return;
    }
    stack<int> st;
    while(x){
        st.push((int)(x%10));
        x/=10;
    }
    while(st.size()){
        cout<<st.top();
        st.pop();
    }
    cout<<"\n";
}
#include<bits/stdc++.h>
#define int long long
using namespace std;
int T=1;
class qst {
    private:
        int a,b,c,d;
        void print(__int128 x) {
            if(x==0) {
                cout<<0<<"\n";
                return;
            }
            stack<int> st;
            while(x) {
                st.push((int)(x%10));
                x/=10;
            }
            while(st.size()) {
                cout<<st.top();
                st.pop();
            }
            cout<<"\n";
        }
    public:
        void solve() {
            cin>>a>>b>>c>>d;
            __int128 ans=a;
            ans+=b;
            ans+=c;
            ans+=d;
            print(ans);
        }
};
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);//cout.tie(0);
    cin>>T;
    while(T--) {
        qst a;
        a.solve();
    }

}