题解 | #Digital Roots#
Digital Roots
https://www.nowcoder.com/practice/cef727d0af33479c9fb4a9c120702414
#include<iostream>
#include<string>
using namespace std;
int char2int(char c) {
return c - '0';
}
char int2char(int d) {
return d + '0';
}
int main() {
string number_str;
while (cin >> number_str) {
while (number_str.size() != 1) {
int sum = 0;
for (int i = 0; i < number_str.size(); i++) {
sum = sum + char2int(number_str[i]);
}
number_str = to_string(sum);
}
cout << number_str << endl;
}
}

