Digital Roots

时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte
总提交: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的更多相关文章

  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. 解题报告:hdu1013 Digital Roots

    2017-09-07 22:02:01 writer:pprp 简单的水题,但是需要对最初的部分进行处理,防止溢出 /* @theme: hdu 1013 Digital roots @writer: ...

  8. HDU - 1310 - Digital Roots

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

  9. Eddy's digital Roots

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

随机推荐

  1. *HDU 1286,2824欧拉函数

    #include<iostream> #include<string> #include<cstdio> #include<cmath> #includ ...

  2. vector容器的用法

    转自一篇博客^-^: 1 基本操作 (1)头文件#include<vector>. (2)创建vector对象,vector<int> vec; (3)尾部插入数字:vec.p ...

  3. Linux下JDK安装笔记

    环境说明: Linux版本: CentOS6.2   JDK:jdk-7u60-linux-x64.tar.gz 1.下载jdk-7u60-linux-x64.tar.gz,本人是放到了~/工具 目录 ...

  4. 定时调度模块:sched

    """A generally useful event scheduler class. 事件调度器类 Each instance of this class manag ...

  5. java 中设置session失效时间

    程序中session都有一个默认的过期时间,其中tomcat中的默认时间为30分钟,根据需要我们可以去手动设置session的过期时间,以下是设置session的过期时间的三个方法:1.在tomcat ...

  6. SUSE命令

    本人很喜欢Suse,在工作中也很喜欢总结关于Suse的经验教训,下面就这个问题来详细说说Suse常用命令.Suse常用命令的问题希望对你有所帮助.看完本文你肯定有不少收获,希望本文能教会你更多关于Su ...

  7. SQL ORDER BY 子句

    ORDER BY 语句用于对结果集进行排序. ORDER BY 语句 ORDER BY 语句用于根据指定的列对结果集进行排序. ORDER BY 语句默认按照升序对记录进行排序. 如果您希望按照降序对 ...

  8. JDBC操作

    String sql = "SELECT * from lib where name = ?";List<Lib> list = getJdbcTemplate().q ...

  9. Xcode命令行生成Bitcode静态库

    近两三年一直在做静态库开发 1.在Xcode工程中创建静态库的Target,最初是手动Build出真机的.a文件,模拟器的.a文件,然后再用命令行合并 2.后来一些特殊的开发者,要求加入特殊的功能,或 ...

  10. WEB语言转义总结

    后台字符串嵌入前台语言输出   web语言分为后台和前台,如果后台语言嵌入方式将字符串输出到前台语言中,需要按照前台语言的要求进行转义. 因为前台各个语言都有自身的保留字符, 用于规定自身的语法格式, ...