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. PyQt4.11.3(python3.4+QT4)ui文件生成py文件

    最近开始接触学习Python,所以想用QT弄个窗体程序出来玩玩,环境是Python3.4.2.PyQt4.11.3-Py3.4.Win7.用PyQt自带的Designer设计出一个窗体ui文件后,需要 ...

  2. javaweb jsp页面上传excel文件

    servlet: private static final long FILE_MAX_SIZE = 4 * 1024 * 1024; if (!ServletFileUpload.isMultipa ...

  3. 学习Emacs

    1.http://ergoemacs.org/emacs/emacs.html 2.Debian7安装emacs24 http://my.oschina.net/xuzhouyu/blog/14954 ...

  4. 激活前一个程序(注册全局消息,使用Mutex探测,如果已经占用就广播消息通知第一个程序,然后第一个程序做出响应)

    unit MultInst; interface const MI_QUERYWINDOWHANDLE = ; MI_RESPONDWINDOWHANDLE = ; MI_ERROR_NONE = ; ...

  5. QT自定义窗口(模拟MainWindow)

    在这里自定义窗口是通过继承于QFrame,内部分为上下两部分,上半部分就是标题栏,下面是窗口的具体内容.上下两部分通过布局固定位置.最后窗口的各种鼠标拖动,缩放,等操作通过添加鼠标事件来完成一个窗口的 ...

  6. SQL Server 2008空间数据应用系列十一:提取MapInfo地图数据中的空间数据解决方案

    原文:SQL Server 2008空间数据应用系列十一:提取MapInfo地图数据中的空间数据解决方案 友情提示,您阅读本篇博文的先决条件如下: 1.本文示例基于Microsoft SQL Serv ...

  7. 匿名函数中undefined形参疑问(转载)

    唉,基本功不扎实,昨天在微博上问了个问题,就匿名函数中undefined形参,不知道是干什么用的. 经常看到这样的匿名函数代码: ;(function( $, window, document,und ...

  8. LeeCode-Rotate Array

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array  ...

  9. GridBagLayout占多行效果注意

    如果想要出现按钮2占两行的效果,必须按键3.按钮4同时存在且同时可见. 如果缺少按钮4,则按钮2不会占两行: 如果缺少按钮3.4,则按钮2也不会占两行. package com.wst.bj; imp ...

  10. hdu 4751 Divide Groups(dfs染色 或 2-sat)

    Problem Description   This year is the 60th anniversary of NJUST, and to make the celebration more c ...