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 <iostream>
using namespace std; int main(int argc, char *argv[])
{
char c;
int sum = 0; while(c = getchar())
{
if(c == '\n')
{
cout << sum << endl; c = getchar();
if(c == '0')
break;
else
sum = c - '0'; continue;
} sum += c - '0'; if(sum > 9)
{
sum = sum%10 + sum/10;
} } return 0;
}
 
 c – '0' 表示对0的距离

HDU 1006 Digital Roots的更多相关文章

  1. HDU 1013 Digital Roots【字符串,水】

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

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

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

  3. HDU 1013 Digital Roots(字符串)

    Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...

  4. HDU 1013.Digital Roots【模拟或数论】【8月16】

    Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...

  5. HDU OJ Digital Roots 题目1013

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

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

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

  7. HDU - 1310 - Digital Roots

    先上题目: Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  8. HDU 1013 Digital Roots 题解

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

  9. hdu 1013 Digital Roots

    #include <stdio.h> int main(void) { int m,i;char n[10000]; while(scanf("%s",&n)= ...

随机推荐

  1. 批处理-Java JDK环境变量配置

    setx /M JAVA_HOME "C:\Program Files\Java\jdk1.8.0_131" setx /M CLASSPATH ".;%%JAVA_HO ...

  2. Scrum冲刺阶段7

    成员今日完成的任务 人员 任务 何承华 美化会员查看安排界面 陈宇 后端设计 丁培辉 美化会员查看界面 温志铭 会员查看界面设计 杨宇潇 会员查看界面设计 张主强 服务器构建 成员遇到的问题 人员 问 ...

  3. idea启动springboot+jsp项目出现404

    场景:用IntelliJ IDEA 启动 springBoot项目访问出现404,很皮,因为我用eclipse开发时都是正常的,找了很久,什么加注释掉<scope>provided< ...

  4. python学习基础总结

    看了一篇python基础的博客   感觉写的很好,总结的很到位,原地址为   http://blog.csdn.net/iloveyin/article/details/38754231 ****** ...

  5. maven阿里云仓库配置

    为了加速项目构建,在maven的settings.xml 文件里配置mirrors的子节点,添加如下mirror: <mirrors> <mirror> <id>a ...

  6. windows kafka 环境搭建踩坑记

    版本介绍(64位): Windows 10 JDK1.8.0_171 zookeeper-3.4.8/ kafka_2.11-0.10.0.1.tgz 点击链接进行下载 1. JDK安装和环境搭建 自 ...

  7. temp-重庆银行

    重庆现场部署环境(开发环境)说明 : 数据库 172.16.69.95:1521:orcl      ilink/ilink123        sys/manager(dba权限) 1, Linux ...

  8. appium + java + WebDriverAgent实现IOS app启动

    Appium v1.8.1 <dependency>    <groupId>io.appium</groupId>    <artifactId>ja ...

  9. NIOS II 之串口学习

    UART中有6个寄存器分别为control, status, rxdata, txdata, divisor,endofpacket. 的寄存器是16位位宽的. UART会产生一个高电平的中断,当接收 ...

  10. 用mplayer从视频中按周期提取帧

    使用方法:extract file time step folder time 设置时间长度 step 设置周期 均以秒(s)为单位 贡献:1. 从视频文件中周期性提取图片:2. Windows下批处 ...