hdu1013 Digital Roots
来源:互联网 发布:免费时时彩网站源码 编辑:程序博客网 时间:2024/06/10 07:43
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<stdio.h>#include<string.h>char a[10005];int main(){ while(scanf("%s",a),strcmp(a,"0")) { int i,len,sum=0; len=strlen(a); for(i=0;i<len;i++) sum=a[i]-'0'+sum; printf("%d\n",(sum-1)%9+1); } return 0;}
Polynomial remainder theorem
阅读全文
0 0
- HDU1013 Digital Roots
- hdu1013 Digital Roots
- hdu1013 Digital Roots
- hdu1013(Digital Roots)
- HDU1013 Digital Roots
- hdu1013-Digital Roots
- hdu1013 Digital Roots
- hdu1013 Digital Roots
- hdu1013:Digital Roots
- hdu1013 Digital Roots 数论
- hdu1013 Digital Roots
- HDU1013 Digital Roots
- HDU1013 Digital Roots
- HDU1013 Digital Roots
- Digital Roots—HDU1013
- HDU1013 POJ1519 Digital Roots
- hdu1013 Digital Roots
- HDU1013 Digital Roots
- 电脑作为服务器,安卓手机作为客户端,通过Socket传输图片
- [js]03css基础
- 我的第一篇博客
- 域服务篇 05. 用户 ❀ Windows Server 2016
- adb命令打开系统设置界面
- hdu1013 Digital Roots
- 将framework 发布到cocoapods
- intellij idea使用指南—— 导入Eclipse的Web项目
- 严重: Exception starting filter struts2 Unable to load configuration
- LeetCode 205. Isomorphic Strings
- 【美团面试】不开辟新的内存空间实现数组去重
- TextView 中SpannableString应用,让你灵活玩转TextView
- LRU缓存实现(Java)
- 数组奇偶划分