Digital Roots

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 67689    Accepted Submission(s): 21144
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
 

——————————————————————————————————————————————————————————————————
题目的意思是累加每位和,若结果大于9,则继续累加


#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
char a[1000005];
int main()
{
int k, sum,sum1;
while (~scanf(" %s", a))
{
if (strcmp(a, "0") == 0)
break;
k = strlen(a);
sum = 0;
for (int i = 0; i < k; i++)
{
sum = sum + a[i] - '0';
} while (sum>9)
{
sum1 = 0;
while (sum != 0)
{
sum1 = sum1 + sum % 10;
sum /= 10;
}
sum = sum1;
}
printf("%d\n", sum); }
return 0; }

Digital Roots—HDU1013 2016-05-06 10:25 85人阅读 评论(0) 收藏的更多相关文章

  1. Digital Roots 分类: HDU 2015-06-19 22:56 13人阅读 评论(0) 收藏

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

  2. 山东理工大学第七届ACM校赛-最大收益问题 分类: 比赛 2015-06-26 10:25 51人阅读 评论(0) 收藏

    最大收益问题 Time Limit: 2000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 铁牌狗最近迷上了一款游戏,但铁牌狗实在是太笨了,他还是要请求你的帮助. 有 ...

  3. 博弈论入门小结 分类: ACM TYPE 2014-08-31 10:15 73人阅读 评论(0) 收藏

    文章原地址:http://blog.csdn.net/zhangxiang0125/article/details/6174639 博弈论:是二人或多人在平等的对局中各自利用对方的策略变换自己的对抗策 ...

  4. DateTime日期格式获取 分类: C# 2014-04-15 10:36 233人阅读 评论(0) 收藏

    c#.net 获取时间年月日时分秒格式 //获取日期+时间 DateTime.Now.ToString();            // 2008-9-4 20:02:10 DateTime.Now. ...

  5. Financial Management 分类: POJ 2015-06-11 10:51 12人阅读 评论(0) 收藏

    Financial Management Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 164431   Accepted: ...

  6. C#中的线程(上)-入门 分类: C# 线程 2015-03-09 10:56 53人阅读 评论(0) 收藏

    1.     概述与概念 C#支持通过多线程并行地执行代码,一个线程有它独立的执行路径,能够与其它的线程同时地运行.一个C#程序开始于一个单线程,这个单线程是被CLR和操作系统(也称为"主线 ...

  7. Hdu1728 逃离迷宫 2017-01-17 10:56 81人阅读 评论(0) 收藏

    逃离迷宫 Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submissi ...

  8. Codeforces758D Ability To Convert 2017-01-20 10:29 231人阅读 评论(0) 收藏

    D. Ability To Convert time limit per test 1 second memory limit per test 256 megabytes input standar ...

  9. POI操作Excel常用方法总结 分类: B1_JAVA 2013-08-23 10:01 349人阅读 评论(0) 收藏

    转载自:http://blog.csdn.net/xjun15/article/details/5805429     一. POI简介               Apache POI是Apache ...

随机推荐

  1. 5A - 超级楼梯

    有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法? Input 输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每行包含一个整数M(1< ...

  2. 使用GrabCut提取前景图像的示范代码

    #include<opencv2/opencv.hpp> bool selectObject = false; cv::Point origin; cv::Rect selection; ...

  3. IIS7.0上传在大小限制

    修改 IIS7的上传文件大小限制的方法: 1.打开IIS管理器,并定位于想要修改限制的网站 2.双击右侧窗口中的asp图标 3.展开最下面那个“限制属性”,将最下面的“最大请求实体主体限制”右边属性框 ...

  4. iOS.Library.Architecture

    在用file查看library的architechture时有以下输出: $ file WebPWebP: Mach-O universal binary with 3 architecturesWe ...

  5. java.lang.NoClassDefFoundError: org/apache/ibatis/cursor/Cursor

    因为mybatis的版本和mybatis-spring的版本不兼容导致的,解决方法:mybatis的3.4.0及以上版本用mybatis-spring1.3.0及以上版本:mybatis的3.4.0以 ...

  6. vue 中使用keepAlive状态保持

      keepAlive状态保持 1 主要实现原理,状态保持的路由不会执行生命周期的钩子函数,只有第一次进入页面会执行钩子函数. 2 设置当前页面保持keepAlive 直接在路由meta中配置即可 m ...

  7. php中static静态关键字的使用方法和应用场景

    php中除了常规类和方法的使用,访问控制之外,还有静态关键字static,静态变量可以是局部变量也可以是全局变量,当一个程序段执行完毕时,静态变量并没有消失,它依然存在于内存中,下次在定义时还是以前的 ...

  8. Tinyos学习笔记(二)

    1.TinyOS communication tools java serialApp -comm serial@/dev/ttyUSB0:telosb java net.tinyos.tools.L ...

  9. Codeforces 749D. Leaving Auction set+二分

    D. Leaving Auction time limit per test: 2 seconds memory limit per test:256 megabytes input:standard ...

  10. Java中的四种内部类

    Java中有四种内部类: 成员内部类:定义在另一个类(外部类)的内部,而且与成员属性和方法平级,故称成员内部类.类比于外部类的非静态方法,如果用static修饰就变成了静态内部类 静态内部类:使用st ...