Type: Default 3000ms 512MiB

全局求和

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

题目描述

求输入数据中所有整数的和。

输入格式

输入中直接给出 nn 个整数,没有 nn 作为前缀;请一直读取到文件结束(EOF)。这些整数由空格和/或换行分隔。

满足 1≤n≤4×1061 \le n \le 4\times 10^6,且每个整数的绝对值不超过 10910^9。

输出格式

输出一个整数,表示所有输入整数的和。

样例

1 2 3 4
0
-1 -2 -3 -4
0

提示

本题输入量较大,部分输入输出方式可能无法在时限内完成。使用 C++ 时,建议在 main() 函数开头加入

ios::sync_with_stdio(false);
cin.tie(nullptr);

并使用 cin、cout 进行输入输出。

调用 ios::sync_with_stdio(false) 后,请勿将 cin、cout 与 scanf、printf 等 C 风格输入输出函数混用,否则可能产生非预期的输入输出行为。

参考实现

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define sc second
#define ll long long
using namespace std;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll a = 0, b = 0;
	while (cin >> a)
	{
		b += a;	
	} 
	cout << b;
	return 0;
}

2026新生赛热身赛

Not Attended
Status
Done
Rule
XCPC
Problem
9
Start at
2026-8-29 10:45
End at
2026-9-13 10:45
Duration
360 hour(s)
Host
Partic.
50