输入:
2
1 2 3
20 17 23 54 77 60
输出:
6
251
#include <iostream>
#include <sstream> //stringstream类的头文件
using namespace std;
int main()
{
string s;
stringstream ss;
int n, i, sum, a;
cin >> n;
getline(cin, s); // 读取换行符
for (i=0; i<n; i++)
{
getline(cin, s);
ss.clear();//清空ss
ss<<s;
sum=0;
while (true)
{
ss >> a;
if ( ss.fail() ) break;
sum+=a;
}
cout << sum << endl;
}
}
09-23
4万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交