Digital Roots hdu 1013
来源:互联网 发布:mac ppt安装字体 编辑:程序博客网 时间:2024/05/14 12:33
Digital Roots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 40096 Accepted Submission(s): 12360
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
Source
Greater New York 2000
这个应该就算一个没有算法,但是不大容易过的题目吧。
#include<iostream>#include<cstdio>#include<cstring>#include<math.h>using namespace std;int main(){ int i,l,n,s; int a[10005]; char b[10005]; while(scanf("%s",b)!=EOF) { int flag=1; if(b[0]=='0') break; int h=strlen(b);//1024 4 //printf("h %d h\n",h); for(i=0;i<h;i++) a[i]=b[i]-48; if(h==1) { printf("%d\n",a[0]); } else { while(1) { //if(flag==1) //s=n; /*else*/ if(flag>=2) { for(i=0;i<10000;i++) { //printf("s1 %d 1s\n",s); if(s<int(pow(10,i))) { h=i; break; } } for(i=0;i<h;i++) { a[i]=s%int(pow(10,i+1))/(int(pow(10,i))); } } s=0; for(i=0;i<h;i++) s=s+a[i]; //printf("s2 %d 2s\n",s); if(s<10) { printf("%d\n",s); break; } else if(s==10) { printf("1\n"); break; } else { flag++; } } } } return 0;}
- 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
- hdu 1013 Digital Roots
- HDU 1013Digital Roots
- HDU 1013 Digital Roots
- hdu 1013 Digital Roots
- hdu 1013 Digital Roots
- Digital Roots hdu 1013
- HDU 1013 Digital Roots
- mac shell终端编辑命令行快捷键
- LAMP体验.
- 《40期》 我们要把世纪末日变成重生日
- java Thread状态
- FindViewById
- Digital Roots hdu 1013
- 这些日子
- [Project]心得
- 驭风篇
- 项目总结
- 在兄弟连的第一个项目
- 带着梦想来学习
- 翻老照片,突然想起你们。
- 战争号角已吹响