Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1013
Test instructions: Given a large number, it must be stored in an array, and then the sum of each bit is calculated, if less than 10 the output, if greater than 10, continue to seek it and the sum of each digit.
For example: 1000 9, and for 9000,9000>10, and then 9000 per digit and, the result is 9, in accordance with test instructions, then output.
<span style= "FONT-SIZE:18PX;" > #include <iostream> #include <cstring>using namespace Std;char num[10000];int res (int n) {if (N < 10) return N;int i = 10;int total = 0;while (n/i) {total + = (n% i/(I/10)); i = i * 10;} Total + = n/(I/10); return res (total);} void f (char *n) {int len = strlen (num); for (int i = 0;i < len;i++) A[i] = num[i]-48;int total = 0;for (int i = 0;i < L en;i++) {total + = A[i];} cout << Res (total) << Endl;} int main (int argc, char *argv[]) {while (1) {cin >> num;if (num[0] = =) return 0;f (num);} return 0;} </span>
Hdu_1013_digital Roots (Analog)