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. hashtable and hashmap

    hashmap的bucket 和 ‘负载因子’的介绍 https://blog.csdn.net/wenyiqingnianiii/article/details/52204136

  2. [转]etcd 启用 https

    1, 生成 TLS 秘钥对 2,拷贝密钥对到所有节点 3,配置 etcd 使用证书 4,测试 etcd 是否正常 5,配置 kube-apiserver 使用 CA 连接 etcd 6,测试 kube ...

  3. 在java中,事务是什么?

    一.什么是Java事务通常的观念认为,事务仅与数据库相关.事务必须服从ISO/IEC所制定的ACID原则.ACID是原子性(atomicity).一致性(consistency).隔离性(isolat ...

  4. spring深入学习(一)-----IOC容器

    spring对于java程序员来说,重要性不可言喻,可以想象下如果没有他,我们要多做多少工作,下面一个系列来介绍下spring(5.x版本). spring模块 IOC概念 spring中最重要的两个 ...

  5. Qt HID USB通讯错误

    1.下载hidapi库 链接:https://pan.baidu.com/s/1iQBuTxg-fReN-7GTrCT6SA 提取码:xzqw 2.把库加入qt 转自:https://www.cnbl ...

  6. PHP PDO预定义常量

    以下常量由本扩展模块定义,因此只有在本扩展的模块被编译到PHP中,或者在运行时被动态加载后才有效. 注意: PDO使用类常量自PHP 5.1.以前的版本使用的全局常量形式PDO_PARAM_BOOL中 ...

  7. python线程的同步事件Event

    Event对象: 用于线程间的通信,某个线程需要根据其他线程的状态来判断自己的下一步操作. Event内部定义了一个全局变量:_flag,默认为False. 当_flag = False时,会阻塞当前 ...

  8. 阿里云服务器搭建SS代理教程!!!

    二.搭建教程 1.环境介绍 阿里云服务器ECS(香港): 配置:cpu 1核心.内存 1GB.出网带宽 10Mbps. 系统:CentOS 7.4 64位 2.服务器端搭建 1)使用root用户,分别 ...

  9. poj 3687 Labeling Balls(拓补排序)

    Description Windy has N balls of distinct weights from 1 unit to N units. Now he tries to label them ...

  10. Unicode vs. UTF-8 etc.

    目测是个老问题了.随便一搜,网上各种总结过.这里不辞啰嗦,尽量简洁的备忘一下. 几个链接,有道云笔记链接,都是知乎上几个问题的摘录:阮一峰的日志,1-5 还是值得参考,但是之后的部分则混淆了 Wind ...