题解 | #Digital Roots#
Digital Roots
https://www.nowcoder.com/practice/cef727d0af33479c9fb4a9c120702414
#include<stdio.h> #include<vector> using namespace std; int main(){ int n; while (scanf("%d", &n) != EOF){ while (n >= 10){ vector<int>vec; int k; while (n != 0){ k = n % 10; vec.push_back(k); n = n / 10; } for (int i = 0; i < vec.size(); i++){ n = n + vec[i]; } } printf("%d\n", n); } }