hdoj.1013 Digital Roots 20140728
2014-07-29 18:34
369 查看
Digital Roots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 48289 Accepted Submission(s): 15006
[align=left]Problem Description[/align]
The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are
summed and the process is repeated. This is continued as long as necessary to obtain a single digit.
For example, consider the positive integer 24. Adding the 2 and the 4 yields a value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is not a single digit, the process
must be repeated. Adding the 1 and the 2 yeilds 3, a single digit and also the digital root of 39.
[align=left]Input[/align]
The input file will contain a list of positive integers, one per line. The end of the input will be indicated by an integer value of zero.
[align=left]Output[/align]
For each integer in the input, output its digital root on a separate line of the output.
[align=left]Sample Input[/align]
24 39 0
[align=left]Sample Output[/align]
6 3 [code]#include<stdio.h> int main() { int sum,a; char s[1010],*p; while(gets(s)){ a=0;p=s; while(*p){ a+=*p-'0'; p++; } if(!a) break; sum=a%9; if(!sum) sum=9; printf("%d\n",sum); } return 0; }
[/code]
相关文章推荐
- HDOJ1013 Digital Roots
- Digital Roots(hdoj1013)
- Num 14: HDOJ: 题目1013 : Digital Roots
- HDOJ 1013 Digital Roots
- hdoj 1013 Digital Roots
- HDOJ 1013题Digital Roots 大数,9余数定理
- HDOJ 1013题Digital Roots 大数,9余数定理
- ACM--数字位数相加--HDOJ 1013--Digital Roots--水
- HDOJ1013 Digital Roots
- HDOJ1013 Digital Roots
- HDOJ1013【Digital Roots】
- HDOJ 1013 Digital Roots(大数)
- HDOJ 1013 Digital Roots
- HDOJ HDU 1013 Digital Roots
- hdoj1013_Digital Roots
- 杭电OJ(HDOJ)1013题:Digital Roots(数值分解)
- HDOJ1013 Digital Roots(高精度+数位分离求和)
- HDOJ 1013 Digital Roots
- HDOJ - 1013 - Digital Roots(字符串、范围)
- HDOJ 1013 Digital Roots