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( ...
随机推荐
- php标签云制作——数据表的结构和查询方法
1.数据表的结构: 创建建两张数据表,结构如下: 标签tag表: 文章mood表: 其中mood表中的tag字段,以tag表的id字段+“,”+tag表的id字段, 2.查询方法: 例如:如果需要某篇 ...
- Mysql event学习
我们可能比较熟悉crond,但是mysql也有一个自己的叫event,oracle的叫job. 开启mysql的event有很多种方法,和临时开启.我们在配置文件里面添加参数,随着服务一起开启. 在[ ...
- Chrome浏览器插件推荐大全
如何下载:http://www.cnplugins.com/devtool/ 提示:下载可能版本过旧,推荐搜索喜爱的插件之后前往官网或者github(编译的时候确保node和npm都是最新的版本).或 ...
- mysql维护常用命令
mysql一个字段的值是将其他字段的被容链接一块 UPDATE `tablename` SET 字段1=CONCAT(字段2," ",字段3," ",字段4) ...
- Socket客户端/服务端简单实例
1.client端 package demo.socket; import java.io.BufferedReader;import java.io.IOException;import java. ...
- Windows内核 基本汇编指令
1)用VS2010新建Win32 Console Application,工程名为ACECore,工程建立完成后得到打开文件ACECore.cpp,代码如下: #include "stdaf ...
- Java程序设计 实验五
实 验 报 告 课程:Java 班级: 1353 姓名:李海空 学号:20135329 成绩: 指导教师:娄嘉鹏 实验日期:2015.6. ...
- 【iCore3 双核心板】例程十七:USB_MSC实验——读/写U盘(大容量存储器)
实验指导书及代码包下载: http://pan.baidu.com/s/1qXt1L0o iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
- Python CRC16校验算法
def crc16(x, invert): a = 0xFFFF b = 0xA001 for byte in x: a ^= ord(byte) for i in range(8): last = ...
- js判断字符是否包含字母汉字
<script type="text/javascript"> function check(str) { if (escape(str).indexOf(" ...