zoj 1115
来源:互联网 发布:薛之谦淘宝 编辑:程序博客网 时间:2024/04/28 00:46
Background
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.
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.
Example
Input
24390Output
63
#include <stdio.h>#include <string.h>int main(){int intsum(int n);int n=0,i;char str[1024]={'\0'};while (scanf("%s",str)!=EOF&&str[0]!='0'){n=0;for (i=0;i<strlen(str);i++){n=str[i]-'0'+n;}n=intsum(n);printf("%d\n",n);}return 0;}int intsum(int n){int sum=0;if (n<10){return n;}while (n>0){sum+=n%10;n=n/10;}while(sum>9){sum=intsum(sum);}return sum;}
- ZOJ 1115
- zoj 1115
- ZOJ-1115
- zoj 1115
- ZOJ 1115
- zoj-1115
- [ACM] ZOJ 1115
- 浙大ACM-ZOJ 1115
- ZOJ Problem Set - 1115
- zoj 1115 Digital Roots
- ZOJ 1115 解题报告
- ZOJ 1115-Digital Roots
- zoj 1115 Digital Roots
- ZOJ 1115 Digital Roots
- ZOJ 1115 Digital Roots
- zoj 1115 Digital Roots
- ZOJ 1115 Digital Roots
- zoj 1115
- vs2010 想用.net2.0,3,0或者其它低版本的框架的解决办法
- zoj 1067
- 带着你的思想去工作
- IO同步与异步
- 百万商业圈小型企业云ERP总体开发规划
- zoj 1115
- Java Iterator与ListIterator
- linux常用头文件详解
- 六、数组(例1---声明和初始化)
- zoj 1201
- poj 2406:Power Strings(KMP)
- Java 创建简单的WebService
- 六、数组(例2---数组的访问)
- zoj 1216