`

Digital Roots

acm 
阅读更多
题目的链接为:http://acm.njupt.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1028
题目为:
Digital Roots
时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte
总提交:329            测试通过:112

描述


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

题意就不写了,是个人就看得明白。重点是,这本身一道极其水的题目,却在我没有考虑输入的数字可能无限大的情况下,硬是WA了N次。我都佩服我自己了....考虑问题居然这样不经过大脑。
#include<iostream>
using namespace std;
int main(){
    
    string str;
    while(cin>>str&&str!="0"){
            
        int num=0;                  
        for(int i=0;i<str.length();i++){
                   
                   num+=str[i]-'0';
                   if(num>9){
                      num=num/10+num%10;          
                   }
        }    
        cout<<num<<endl;                      
    }
    
    system("pause");    
    return 0;
}
分享到:
评论

相关推荐

    zoj 题库 详细解答 解题代码

    该题目主要考察了数字处理能力,要求解决 Digital Roots 问题。该问题的解决需要对数字处理有深入的理解。 知识点:数字处理、数字操作、数值运算。 10. ZOJ Problem Set – 1151 Word Reversal 该题目主要考察了...

    ZOJ完全解题报告,涵盖了几十道ZOJ上面的编程题,有很详细的解题方法供参阅

    7. **Digital Roots 1115** - 数字根是数字处理的一个经典问题,可能需要理解数字运算和循环结构,可能涉及到模运算。 8. **Word Reversal 1151** - 词汇逆序可能涉及到字符串操作,如双指针技术或栈的使用,用于...

    经典ACM题总结(中山大学)

    9. **Digital Roots** - 题目编号:1115 - 难度等级:基础 - 主要考察点:数字操作。 - 实现思路:给定一个正整数,重复将它的各个位相加直到结果为一位数。这涉及到对数字的基本操作和循环处理。 10. **Word ...

    全面的ACM题目分类

    7. **数学函数与常数**:1491 Pi涉及圆周率的计算,1517 u Calculate e要求计算e的近似值,1519 Digital Roots涉及到数字根的计算。 8. **逻辑与博弈**:1218 the drunk jailer可能需要理解概率和逻辑推理,1579 ...

    ZJU_ACM_All_Anwer 搞编程的都知道的浙江大学A 题库.本书 集了所有经 Z 题解集,集合并附 Mathimaticsumerical algorithms 数值算法

    1115 Digital Roots 简单题 1113 u Calculate e 简单题 1152 A Mathematical Curiosity 简单题 1154 Niven Numbers 简单题 1160 Biorhythms 简单题 1163 The Staircases 简单题 1177 K-Magic Number ...

    浙江大学ACM题解/ZJU 题型分类

    1115 Digital Roots 简单题 1113 u Calculate e 简单题 1152 A Mathematical Curiosity 简单题 1154 Niven Numbers 简单题 1160 Biorhythms 简单题 1163 The Staircases 简单题 1177 K-Magic Number ...

    Digital image processing techniques for detecting, quantifying

    reasons: to limit the length of the paper and because methods dealing with roots, seeds and fruits have some peculiarities that would warrant a specific survey. The selected proposals are divided into...

    roots-example-project.com, 根堆栈工程( 格,基岩,Sage ).zip

    roots-example-project.com, 根堆栈工程( 格,基岩,Sage ) 根示例项目这里知识库是如何集成和使用以下项目的一个示例:基岩网格Sage ( 带土壤的)有关...这个项目是一个完整的工作示例,部署在 Digital Ocean 512MB dro

    数字集成电路英文课件:Chapter 1 Deep Submicron Digital IC Design.ppt

    The introduction then shifts to the historical roots of computing, showcasing Charles Babbage's Difference Engine as an early example of a mechanical computer. The presentation illustrates the ...

    北京理工大学信号与系统实验报告6_离散时间系统的z域分析报告.docx

    Digital signal processing: A computer-based approach. McGraw-Hill. 六、附加内容 离散时间系统的z域分析在实际应用中有广泛的应用前景,如信号处理、控制系统、通信系统等。因此,深入理解离散时间系统的z域...

    浙大oj试题代码

    8. 1115 digitai roots.txt:这个题目可能涉及数字根(digital root),即一个整数的所有位数相加,直到结果只剩一位数的过程。 9. 1240.txt:没有具体信息,可能是一道基础算法题,例如搜索、排序或者递归问题。 10...

    Teradata Messages (English)

    - **DBC/1012**: The original name of the Teradata Database system, indicating its historical roots. - **IFP (Interface Processing Unit)**: An older term for the component responsible for handling ...

    golang解析数字证书

    1. **数字证书(Digital Certificate)**:也称为X.509证书,是一种标准格式,用于在网络上证明实体的身份。它包含公钥、主体信息(如组织名、域名)、颁发者信息以及有效期等。 2. **公钥和私钥(Public Key and ...

    上海交大ACM模板,ACMer值得一看

    #### 1.6 数字树 (Digital Tree) 数字树也称为Trie树,是一种用于处理字符串的树形结构。在搜索和插入操作上具有很高的效率,广泛应用于词典、搜索引擎等领域。 #### 1.7 区间树 (Segment Tree) 区间树是一种支持...

    An Introduction to Cryptography - 2nd Edition - 2007

    1.5 Primitive Roots . . . . . . . . . . . . . . . . . . . . . . . . . . 44 1.6 The Index Calculus and Power Residues . . . . . . . . . . 51 1.7 Legendre, Jacobi, & Quadratic Reciprocity . . . . . . . ...

    Channel Coding in Communication Networks

    Homage to Alain Glavieux. . . . . . . . . ....Chapter 1....1.1. Introduction: the Shannon paradigm ....1.2. Principal coding functions ....1.2.1. Source coding ....1.2.2. Channel coding ....1.2.3. Cryptography ....

    BobBuilder_app

    NoSQL: A grass roots movement to replace relational databases with more relevant and specialized storage systems to the application in question. These systems are usually designed for performance. ...

Global site tag (gtag.js) - Google Analytics