/*Digital Roots

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

Total Submission(s): 58506    Accepted Submission(s): 18275

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

Source

Greater New York 2000 

Recommend

We have carefully selected several similar problems for you:  1008 1017 1012 1018 1005 #include<stdio.h>

*/越简单越小心  数字与字符之间的转换

#include<string.h>

int ji(int n)

{

 int sum=0;

 while(n!=0)

 {

  sum+=n%10;

  n=n/10;

 }

 if(sum/10!=0) ji(sum);

 else return sum;

}

int main()

{

 char s[1001];

 int m;

 while(scanf("%s",s),s[0]!='0')

    {

     int n=0,k;

     k=strlen(s);

     for(int i=0;i<k;i++)

       n+=s[i]-'0';

  printf("%d\n",ji(n));

    }

    return 0;

}

HDU OJ Digital Roots 题目1013的更多相关文章

  1. HDU - 1310 - Digital Roots

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

  2. HDU 1006 Digital Roots

    Problem Description The digital root of a positive integer is found by summing the digits of the int ...

  3. HDU OJ Max sum 题目1003

     #include <iostream> #include<stdio.h> #include<stdlib.h> using namespace std; i ...

  4. HDU 1013 Digital Roots【字符串,水】

    Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  5. HDU 1013 Digital Roots(to_string的具体运用)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1013 Digital Roots Time Limit: 2000/1000 MS (Java/Othe ...

  6. 【九度OJ】题目1124:Digital Roots 解题报告

    [九度OJ]题目1124:Digital Roots 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1124 题目描述: T ...

  7. HDU 1013 Digital Roots(字符串)

    Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...

  8. HDU 1013.Digital Roots【模拟或数论】【8月16】

    Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...

  9. HDU 1013 Digital Roots(字符串,大数,九余数定理)

    Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

随机推荐

  1. “公共语言规范”(CLS)

    一.什么是“公共语言规范”(CLS) 定义了一个最小公共集,任何编译器只有支持这个功能集,生成的类型才能兼容其他符合CLS.面向CLR的语言生成的组件 二.CLS规则 类型的每个成员要么是字段(数据) ...

  2. 选择 React Native 的理由

    转载:选择 React Native 的理由 从开始知道 React Native 到现在已经过了5个月,真实的试用也经历了三个月的时间.阅读文档开始,了解是什么,到简单的理解为什么,都是在聆听不同的 ...

  3. web服务端安全之文件上传漏洞

    一.文件上传漏洞的原理 由于程序代码未对用户提交的文件进行严格的分析和检查,导致攻击者可以上传可执行的代码文件,从而获取web应用的控制权限. 常见于上传功能,富文本编辑器. 二.文件上传漏洞的防御 ...

  4. django 启动nginx的时候,报端口被占用的问题

    Nginx [emerg] listen() to 0.0.0.0:80, backlog 511 failed (98: Address already in use) Nginx更新后经常遇到这样 ...

  5. 凡信(超仿微信Android版)开源了,内有源码下载 -

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 凡信(超仿微信Android版)开源了,内有源码下载 - IM Geek开发者社区-移动 ...

  6. android 注册广播接受者

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 动态注册 静态注册 动态注册是 通过java代码,注册. 静态注册 是xml清单文件中 ...

  7. 3、Redis中对String类型的操作命令

    写在前面的话:读书破万卷,编码如有神 -------------------------------------------------------------------- ------------ ...

  8. jmeter3.3—插件管理器的安装

    一.介绍JMeter Plugins 一直以来, JMeter Plugins 为我们提供了很多高价值的JMeter插件,比如: 用于服务器性能监视的 PerfMon Metrics Collecto ...

  9. EJB (Enterprise Java Bean) 理解

    做开发有段时间了,一直似懂非懂的. http://blog.csdn.net/jojo52013145/article/details/5783677

  10. 华为S5300系列升级固件S5300SI-V200R001C00SPC300.cc

    附带web,V200版本的第一个固件. 附件: 链接:https://pan.baidu.com/s/1QyXIIVho9AkhxUFYJYAkcw  密码:gaxm