Hdu 1013 Digital Roots
2014-11-16 16:36
387 查看
Digital Roots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 50643 Accepted Submission(s): 15810
[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
[align=left]合九法:一个数的数字跟等于这个数模9,也等于个个位所有数之和模9,是9的话就直接输出[/align]
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s;
while(1)
{
cin>>s;
if(s=="0")
break;
int n=0;
for(int i=0;i<s.size();i++)
{
n += (s[i]-'0');
n %= 9;
}
if(n==0)
cout<<9<<endl;
else
cout<<n<<endl;
}
return 0;
}
[align=left] [/align]
相关文章推荐
- HDU1013 POJ1519 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
- hdu-1013-Digital Roots
- HDOJ 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(模拟 || 数论)
- HDU 1013 Digital Roots【水题】
- hdu 1013 Digital Roots
- HDU 1013 Digital Roots 题解