Digital Roots

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 53625    Accepted Submission(s): 16747

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
 
分析:
1  10  19(10)  28(10)  ....
2  11  20        29(11)
3  12  21        30
4  13  22       .....
5  14  23
6  15  24
7  16  25
8  17  26
9  18  27
 
#include<stdio.h>
#include<string.h>
int main(){
    long int sum,len,i;
    char num[10000];
    while(scanf("%s",num) && num[0]!='0'){
        
        len=strlen(num);
        sum=0;
        for(i=0;i<len;i++)
            sum+=num[i]-'0';
        sum=sum%9;
        if(sum>0)
            printf("%d\n",sum%9);
        else
            printf("9\n");
    }
    return 0;
}

杭电1013-Digitai Root(这是一道考研编程题-天大2015)的更多相关文章

  1. 杭电 1013 Digital Roots

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1013 反思:思路很简单,但是注意各位数加起来等于10的情况以及输入0的时候结束程序该怎么去表达 #in ...

  2. HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...

  3. HDU 4639 hehe 杭电2013多校联赛第四场1008题

    解题报告:题目的意思是输入一个字符串,并规定,里面的“hehe”可以用"wqnmlgb"来代替,也可以不代替,问输入的这个字符串在经过相关的代替之后可以有多少种不同的形态.先打一个 ...

  4. 杭电oj1860:统计字符(字符串hash / 水题)

    统计字符 题目链接 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem D ...

  5. 杭电OJ2039——三角形(c++)(易错题:数据类型不确定)

    三角形 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submis ...

  6. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  7. 杭电 1272 POJ 1308 小希的迷宫

    这道题是我学了并查集过后做的第三个题,教我们的学姐说这是并查集的基础题,所以有必要牢牢掌握. 下面就我做这道题的经验,给大家一些建议吧!当然,我的建议不是最好的,还请各位大神指出我的错误来,我也好改正 ...

  8. 杭电ACM题单

    杭电acm题目分类版本1 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 1007 经典问题,最 ...

  9. 用python爬取杭电oj的数据

    暑假集训主要是在杭电oj上面刷题,白天与算法作斗争,晚上望干点自己喜欢的事情! 首先,确定要爬取哪些数据: 如上图所示,题目ID,名称,accepted,submissions,都很有用. 查看源代码 ...

随机推荐

  1. RAC GI安装,报"Task resolv.conf Integerity"验证失败

    安装12.1.0.2 rac测试环境的时候,报"Task resolv.conf Integerity"验证失败 解决方案: 因为测试环境,没有使用DNS,删除resolv.con ...

  2. Java基础之写文件——使用带缓冲的Writer写文件(WriterOutputToFile)

    控制台程序,将一列字符串写入到文件中. import java.io.*; import java.nio.file.*; import java.nio.charset.Charset; publi ...

  3. [翻译] java NIO 教程---介绍

    原文地址:http://tutorials.jenkov.com/java-nio/index.html Java NIO(new IO)是从java1.4之后的对IO API的另一种选择,即对标准j ...

  4. jQuery 扩展功能

    源码如下: /*! * 说明:Jquery库扩展 * 创建时间: leo 2016/10/13 */ (function (window, jQuery, undefined) { jQuery.ex ...

  5. ps 简介

    1. ps 简介ps 命令就是最根本相应情况下也是相当强大地进程查看命令.运用该命令可以确定有哪些进程正在运行和运行地状态. 进程 是否结束.进程有没有僵死.哪些进程占用了过多地资源等等.总之大部分信 ...

  6. Orthomcl的详细使用

    参考了众多文章并结合实际操作后的感想. 参考:http://www.plob.org/2013/09/18/6174.html 参考:http://www.plob.org/2012/06/12/22 ...

  7. struts2 标签字体大小

    <style type="text/css"> label{ font-size: 20px; } </style> <s:textfield nam ...

  8. PHP中9大缓存技术总结(转载 http://www.php100.com/html/php/lei/2015/0919/8969.html)

    PHP中9大缓存技术总结 来源:   时间:2015-09-19 02:40:33   阅读数:57767 分享到: 12 [导读] 1.全页面静态化缓存也就是将页面全部生成html静态页面,用户访问 ...

  9. 玩转HTML5移动页面(动效篇)(转载)

    本文转载自: 玩转HTML5移动页面(动效篇)

  10. Logic and Fault simulation

    fault simulation是指对fault circuit的simulation,来locate manufacturing defects并且进行fault diagnosis. logic ...