fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int main(){
  5. long int S;
  6. string str;
  7. while(cin >> str && str != "0" ){
  8. S=0;
  9. for(int i=0;i<str.size() ; i++){
  10. S += str[i]-'0';
  11. }
  12. cout << S <<endl;
  13. }
  14.  
  15. }
  16.  
Success #stdin #stdout 0s 15240KB
stdin
123
55
1000
0
stdout
6
10
1