HDUJ 1013 Digital Roots
来源:互联网 发布:数据库设计经典案例 编辑:程序博客网 时间:2024/04/30 20:55
Digital Roots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 48330 Accepted Submission(s): 15023
Problem Description
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.
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.
Input
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.
Output
For each integer in the input, output its digital root on a separate line of the output.
Sample Input
24390
Sample Output
63
#include<iostream>#include<cstring>using namespace std;int main(){char str[10001];while(cin>>str){if(str[0]=='0') break;int len=strlen(str);int s=0;for(int i=0;i<len;i++)s += str[i]-'0';while(true){int t=0;while(s){t += s%10;s /= 10;}s = t;if(s<10) break;}cout<<s<<endl;}return 0;}
0 0
- HDUJ 1013 Digital Roots
- HDU 1013 Digital Roots
- HDU 1013 Digital Roots
- 1013:Digital Roots
- hdu 1013 Digital Roots
- HDOJ 1013 Digital Roots
- HDU 1013 Digital Roots
- 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 1013 Digital Roots
- hdu 1013 Digital Roots
- 1013 Digital Roots
- 1013 Digital Roots
- 使用STL的next_permutation函数生成全排列(C++)
- bzoj1050 [HAOI2006]旅行comf
- PL/SQL编程基础(章节摘要)
- hdu 2393 Higher Math
- (HTML学习)常用标签 超链接颜色控制
- HDUJ 1013 Digital Roots
- JavaFX文档(2)什么是JavaFX
- EBS R12多组织访问控制
- C++ map的基本操作和使用
- FileReader读取中文txt文件编码丢失问题
- 走好下一步为要
- HDU1285 确定比赛名次 【拓扑排序】
- 程序员的自我修养——操作系统篇
- C/C++ sort函数的用法