#29557: 求解

#### chenpin513@gmail.com (132)

School : 浙江省杭州外国语学校
ID : 157917
2022-03-12 18:38:21
c813. 11332 - Summing Digits -- | From: [140.115.227.223] | Post Date : 2022-03-12 00:04

#include <bits/stdc++.h>

using namespace std;

int func(string s_num){

int sum = 0;

for(int i = 0 ; i < s_num.length() ; i++){

sum += s_num[i] - '0';

}

if(sum / 10 >= 1){

string str = to_string(sum);

func(str);

}

else{

return sum;

}

}

int main()

{

string num;

while(cin >> num && num != "0"){

cout << func(num) << endl;

}

}

#29565: Re:求解

#### cges30901 (cges30901)

School : No School
ID : 30877
2023-09-20 12:39:07
c813. 11332 - Summing Digits -- | From: [27.247.4.185] | Post Date : 2022-03-12 10:54

#include <bits/stdc++.h>

using namespace std;

int func(string s_num){

int sum = 0;

for(int i = 0 ; i < s_num.length() ; i++){

sum += s_num[i] - '0';

}

if(sum / 10 >= 1){

string str = to_string(sum);

func(str);

}

else{

return sum;

}

}

int main()

{

string num;

while(cin >> num && num != "0"){

cout << func(num) << endl;

}

}

ZeroJudge Forum