跳到正文

题解

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

yzyUUU约 2 分钟
原文
文章信息与版本

文章信息

收录
2026年7月14日
更新
2026年7月16日
篇幅
约 2 分钟
题目
P17073

版本

  1. v1当前

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

签到题

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


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

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

C++
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";
}

C++
#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();
	}

}
原文