HDU 1013 Digital Roots(大数)
2018-02-21 21:08
549 查看
Digital Roots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 85912 Accepted Submission(s): 26807[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]24390[align=left]Sample Output[/align]63思路:一个数模9等于其各位数字和模9,即题目要求。例如:44%9=8%9;45%9=9%9;但此题若为9则不需要再取模。#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main() {
char s[10000];
while(scanf("%s",s)!=EOF&&s[0]!='0') {
int sum=0;
for(int i=strlen(s)-1; i>=0; i--) {
sum+=s[i]-'0';
sum%=9;
}
if(sum==0)
sum=9;
printf("%d\n",sum);
}
return 0;
}
相关文章推荐
- HDU 1013 Digital Roots (无限大数)
- HDU 1013 Digital Roots 大数 水题
- HDU 1013 Digital Roots (简单题_大数)
- HDU 1013_Digital Roots(大数&模拟)
- HDU1013_Digital Roots【大数】【水题】
- HDU 1013 Digital Roots 大数水题
- HDU-1013-Digital Roots(Java && 大数 && 数根)
- HDU 1013 Digital Roots
- HDU--1013--Digital Roots
- hdu 1013 Digital Roots 用一个大水题来纪念我进入杭电前一万名
- HDU 1013 Digital Roots
- Digital Roots(杭电1013)(字符串处理)(大数)
- hdu 1013 Digital Roots(字符输入,字符串处理)
- HDU_1013 Digital Roots
- HDU 1013 Digital Roots
- HDU-#1013 Digital Roots(九余数定理)
- HDU 1013 Digital Roots
- hdu 1013 Digital Roots (九余数定理)
- HDU-1013 Digital Roots
- hdu 1013 Digital Roots