Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一个数的数字根和其mod 9 是关于9同余的。So: int get_digital_root(const char* num) { int res = 0; for (int i = 0; num[i] != '\0'; ++i) res = (res * 10 + num[i] - '0') % 9; return res == 0 ? 9 : res; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator