题解:P5660 [CSP-J2019] 数字游戏
一个很简单的方法:while(cin>>c) 可以一直读入一个字符直到文件的末尾(EOF)。一个数字字符减去 '0' 就可以得到对应的数字。用一个变量把读到的所有数字加起来就可以了。
#include<bits/stdc++.h>
using namespace std;
int main(){
int s=0;char c;
while(cin>>c)s+=c-'0';
cout<<s;
return 0;
}