#25937: C++


liu76214@gmail.com (Andrew liu)

School : 新竹市立建功高級中學
ID : 92407
IP address : [111.243.122.123]
Last Login :
2021-08-15 15:26:39
c813. 11332 - Summing Digits -- UvaRuby兔 | From: [111.243.107.3] | Post Date : 2021-07-06 00:45

#include <iostream>

 

using namespace std;

 

int main() {

unsigned long long int k = 0;

while (cin >> k) {

unsigned int result = 0;

 

if (k == 0) {

break;

}

 

while (true) {

if (result < 10 && k == 0) {

break;

}

else if (result > 9 && k == 0) {

k = result;

result = 0;

}

result += k % 10;

k /= 10;

}

cout << result << endl;

}

 

return 0;

}

 
ZeroJudge Forum