题解 | #Digital Roots#
Digital Roots
https://www.nowcoder.com/practice/cef727d0af33479c9fb4a9c120702414
#include <iostream> #include <string> using namespace std; int main() { string a; while(cin>>a){ if(a=="0") break; int ans = 0; for(int i=0;i<a.size();++i){ ans+=a[i]-'0'; } while(ans>9){ int su = 0; while(ans!=0){ su += ans%10; ans/=10; } ans = su; } printf("%d\n",ans); } }