題目:
https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=25&page=show_problem&problem=2307
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| #include <iostream>
using namespace std;
int main(){ int n, sum; while(cin >> n){ if(n == 0) break; sum = n; while(sum >= 10){ n = sum; int tmp = 0; while(n > 0){ tmp += n%10; n /= 10; } sum = tmp; } cout << sum << '\n'; } return 0; }
|