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.

 
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
24
39
0
 
Sample Output
6
3
 #include<stdio.h>
#include<string.h>
int s(int sum)
{
int a=,b=;
while(sum!=)
{
a=sum%;
sum=sum/;
b+=a;
}
return b;
}
int main()
{
char a[];
int len;
while(gets(a)&&a[]!='')
{
int sum=;
len=strlen(a);
while(len--)
{
sum+=a[len]-'';
}
while(sum>=)
sum=s(sum);
printf("%d\n",sum);
}
}

WAcode:

 #include<stdio.h>/*原因貌似是因为位数不够。。*/
int main()
{
int n;
while(scanf("%d",&n)==&&n!=)
{
while(n>=)
{
n=n/+n%;
}
printf("%d\n",n);
}
}

Digital Roots(hdoj1013)的更多相关文章

  1. HDOJ 1163 Eddy's digital Roots(九余数定理的应用)

    Problem Description The digital root of a positive integer is found by summing the digits of the int ...

  2. HDU 1013 Digital Roots(字符串,大数,九余数定理)

    Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  3. HDU——1163Eddy's digital Roots(九余数定理+同余定理)

    Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  4. Eddy's digital Roots(九余数定理)

    Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  5. HDU-1163 Eddy's digital Roots(九余数定理)

    Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  6. HDU 1013 Digital Roots(to_string的具体运用)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1013 Digital Roots Time Limit: 2000/1000 MS (Java/Othe ...

  7. 数字色彩的艺术 | The Art Of Digital Color(修订)

    翻译一篇来自2011年的文章,原链地址:https://www.fxguide.com/featured/the-art-of-digital-color/ 在这个时期,DPX日渐式微,ACES方兴未 ...

  8. poj 1284 Primitive Roots (原根)

    Primitive Roots http://poj.org/problem?id=1284 Time Limit: 1000MS   Memory Limit: 10000K       Descr ...

  9. hdu--1013--Digital Roots(字符串)

    Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

随机推荐

  1. 10--动作系统(四)动作类中的reverse方法

    上一篇文章在使用持续动作过程中遇到不少问题,以获取动作类的反系动作尤为突出.所以今天把动作类找了个遍,先将大部分动作类是否实现reverse方法总结如下: T表示实现F表示没有实现. 观察可以发现带T ...

  2. 重读LPTHW-Lesson18-21 函数

    1.def 定义函数,选取合适的函数名,原则是易于理解.阅读.函数名格式与变量命名格式相同,以字母开始,可以包含字母.数字.下划线.函数命名后,把参数放在()中,可以无参数.然后:结束函数命名,开始函 ...

  3. Android进阶练习一

    1.有序广播: https://github.com/wuzhuojun/BroadcastExample 说明: 在manifest.xml设置的广播是静态注册,只要软件安装在手机上广播就能够生效. ...

  4. linux服务器之间拷贝文件和文件夹

    传输文件用法:scp 本机文件目录 远程服务器用户名@服务器IP:/服务器目录 示例:

  5. Best Time to Buy and Sell Stock III 解答

    Question Say you have an array for which the ith element is the price of a given stock on day i. Des ...

  6. UVA 11111-Generalized Matrioshkas(栈)

    题意:有很多层盒子,盒子里面再套盒子,一个盒子可能套多个独立的子盒子,但子盒子的总体积必须小于该盒子,否则不合法,输入给一行数,负数代表左边,正数代表右边,大小表示其体积,如-2,-1,1,2则表示体 ...

  7. oracle常见错误类型

    http://www.cnblogs.com/whyhappy/p/6232258.html

  8. [破解] DRM-内容数据版权加密保护技术学习(上):视频文件打包实现

    1. DRM介绍: DRM,英文全称Digital Rights Management, 可以翻译为:内容数字版权加密保护技术. DRM技术的工作原理是,首先建立数字节目授权中心.编码压缩后的数字节目 ...

  9. Quartz 开源的作业调度框架

    Quartz 是一个开源的作业调度框架,它完全由 Java 写成,并设计用于 J2SE 和 J2EE 应用中.它提供了巨大的灵活性而不牺牲简单性.你能够用它来为执行一个作业而创建简单的或复杂的调度.本 ...

  10. Comet学习资料

    什么是Comet: http://baike.baidu.com/view/577938.htm?fr=ala0_1 Comet介绍: http://www.ibm.com/developerwork ...