Digital Roots 1013
Digital Roots
总提交:456 测试通过:162
描述
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.
输入
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.
输出
For each integer in the input, output its digital root on a separate line of the output.
样例输入
24
39
0
样例输出
6
3
当时数组开辟空间1000 死活通不过,稍大一点就可以
#include <iostream>
#include <cstring>
using namespace std; int main()
{
char num[];
int len;
while(cin.getline(num,)&& num[]!='')
{
len=strlen(num);
int sum=;
for(int i=;i<len;i++)
{
sum+=num[i]-'';//一般程序不用 48 而是0’
if(sum>=)
sum=sum/+sum%; //这个我开学讲过 如何求解一个数的每一位
}
cout<<sum<<endl;
}
return ;
}
Digital Roots 1013的更多相关文章
- HDU 1013 Digital Roots【字符串,水】
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1013 Digital Roots(to_string的具体运用)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1013 Digital Roots Time Limit: 2000/1000 MS (Java/Othe ...
- HDU 1013 Digital Roots(字符串)
Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...
- HDU 1013.Digital Roots【模拟或数论】【8月16】
Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...
- HDU OJ Digital Roots 题目1013
/*Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1013 Digital Roots(字符串,大数,九余数定理)
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 解题报告:hdu1013 Digital Roots
2017-09-07 22:02:01 writer:pprp 简单的水题,但是需要对最初的部分进行处理,防止溢出 /* @theme: hdu 1013 Digital roots @writer: ...
- HDU - 1310 - Digital Roots
先上题目: Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- Eddy's digital Roots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
随机推荐
- Xcode 添加类前缀
按照如下图所示操作后,接下来创建的类就会带有MN的前缀;如果想更换前缀,则替换MN即可!
- Transform a BST to greater sum tree
Given a BST, transform it into greater sum tree where each node contains sum of all nodes greater th ...
- mysql怎么导入大文件的sql文件
这个方法在windows上或者linux上都可以使用 多数人习惯使用phpmyadmin或者一些客户端比如workbench,navicat 但是最有效的是原生的php工具 命令都差不多 请在cmd的 ...
- ThinkPHP 3.2.3 自动加载公共函数文件的方法
方法一.加载默认的公共函数文件 在 ThinkPHP 3.2.3 中,默认的公共函数文件位于公共模块 ./Application/Common 下,访问所有的模块之前都会首先加载公共模块下面的配置文件 ...
- objective-c基础教程——学习小结
objective-c基础教程——学习小结 提纲: 简介 与C语言相比要注意的地方 objective-c高级特性 开发工具介绍(cocoa 工具包的功能,框架,源文件组织:XCode使用介绍) ...
- python随机服务器的双线出口ip发送邮件
#-*- coding:utf-8 -*-import smtplibimport sysimport random import socketfrom email.mime.text import ...
- css3超过指定宽度文字,显示省略号
text-overflow:ellipsis; overflow:hidden; white-space:nowrap; width:200px;
- libgdx actor 透明问题
遇到一个问题,自定义的Actor在使用batch.draw时,其他Actor设置的透明影响到了这个Actor 处理方法为 在自定义Actor中 draw方法中 绘制前,加入 Color color = ...
- Java学习-047-数值格式化及小数位数四舍五入
此小工具类主要用于数值四舍五入.数值格式化输出,很简单,若想深入研究,敬请自行查阅 BigDecimal 或 DecimalFormat 的 API,BigDecimal.setScale(位数,四舍 ...
- DevExpress中的ASPxTreeView 递归显示checknodes并获得选中值
aspx代码 <dx:ASPxTreeView ID="ASPxTreeView1" runat="server"> </dx:ASPxTre ...