/*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. 大数据技术之_13_Azkaban学习_Azkaban(阿兹卡班)介绍 + Azkaban 安装部署 + Azkaban 实战

    一 概述1.1 为什么需要工作流调度系统1.2 常见工作流调度系统1.3 各种调度工具特性对比1.4 Azkaban 与 Oozie 对比二 Azkaban(阿兹卡班) 介绍三 Azkaban 安装部 ...

  2. 1014 Waiting in Line (30)(30 point(s))

    problem Suppose a bank has N windows open for service. There is a yellow line in front of the window ...

  3. 机器学习之路: python 朴素贝叶斯分类器 MultinomialNB 预测新闻类别

    使用python3 学习朴素贝叶斯分类api 设计到字符串提取特征向量 欢迎来到我的git下载源代码: https://github.com/linyi0604/MachineLearning fro ...

  4. [BZOJ3309]DZY Loves Math(莫比乌斯反演+线性筛)

    $\sum\limits_{T=1}^{n}\lfloor\frac{n}{T}\rfloor\lfloor\frac{m}{T}\rfloor\sum\limits_{d|T}f(d)\mu(\fr ...

  5. java设计模式(六)策略模式

    适用于同一操作的不同行为,策略模式定义了一系列的算法,并将每一个算法封装起来,而且使它们可以相互替换,让算法独立于使用它的客户而独立变化,具体应用场景如第三方支付对接不同银行的算法. 要点:1)抽象策 ...

  6. 第一章--Go与web应用

    Go语言构建web应用的特性 可扩展 可维护 模块化 高性能 HTTP简介 HTTP是一种无状态.由文本构成的请求-响应(request-response)协议,这种协议使用的是客户端-服务器(cli ...

  7. JDK源码学习笔记——Enum枚举使用及原理

    一.为什么使用枚举 什么时候应该使用枚举呢?每当需要一组固定的常量的时候,如一周的天数.一年四季等.或者是在我们编译前就知道其包含的所有值的集合. 利用 public final static 完全可 ...

  8. poj 1328 Radar Installation 排序贪心

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 56702   Accepted: 12 ...

  9. Spring_Spring集成Quartz定时任务框架介绍和Cron表达式详解

    在JavaEE系统中,我们会经常用到定时任务,比如每天凌晨生成前天报表,每一小时生成汇总数据等等.我们可以使用java.util.Timer结合java.util.TimerTask来完成这项工作,但 ...

  10. 引子——从Mac OS X的Lion说起

    最近感悟越来愈多,女儿越来越大,头发越来越少,我知道,自己老了. 30岁之后,时间仿佛开闸的河水一样滚滚而去,感觉自己浪费的时间太多.我们不得不承认,先知先觉的人会比我们领先10年甚至更多的身位.所以 ...