HDU OJ Digital Roots 题目1013
/*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的更多相关文章
- HDU - 1310 - Digital Roots
先上题目: Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- HDU 1006 Digital Roots
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
- HDU OJ Max sum 题目1003
#include <iostream> #include<stdio.h> #include<stdlib.h> using namespace std; i ...
- HDU 1013 Digital Roots【字符串,水】
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1013 Digital Roots(to_string的具体运用)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1013 Digital Roots Time Limit: 2000/1000 MS (Java/Othe ...
- 【九度OJ】题目1124:Digital Roots 解题报告
[九度OJ]题目1124:Digital Roots 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1124 题目描述: T ...
- HDU 1013 Digital Roots(字符串)
Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...
- HDU 1013.Digital Roots【模拟或数论】【8月16】
Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...
- HDU 1013 Digital Roots(字符串,大数,九余数定理)
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
随机推荐
- C#拖拽操作
C#的拖拽 本文将以Winform为例 有两个主要的事件: DragEnter 拖拽到区域中触发的事件 DragDrop 当拖拽落下的时候出发此事件 饮水思源 参考博客: http://www.cnb ...
- 防止sql注入的几种方法
一.SQL注入简介 SQL注入是比较常见的网络攻击方式之一,它不是利用操作系统的BUG来实现攻击,而是针对程序员编程时的疏忽,通过SQL语句,实现无帐号登录,甚至篡改数据库. 二.SQL注入攻击的总体 ...
- [Arc081F]Flip and Rectangles
[Arc081F]Flip and Rectangles 试题分析 首先考虑如何操作,发现我们只会选若干行和若干列来进行一次取反. 这个东西相当于什么呢?相当于交点不变,然后这些行和这些列的其它点取反 ...
- 【洛谷】2120:[ZJOI2007]仓库建设【斜率优化DP】
P2120 [ZJOI2007]仓库建设 题目背景 小B的班级数学学到多项式乘法了,于是小B给大家出了个问题:用编程序来解决多项式乘法的问题. 题目描述 L公司有N个工厂,由高到底分布在一座山上. 工 ...
- python开发_tkinter_复选菜单
在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...
- 记一次完整的pc前端整站开发
我所做的项目是一个线上的旅游平台,当然不是大家耳熟能详的那些旅游平台了,项目刚开始也没有必要去评价它的好坏,在这里我就不多说了~这是线上地址有兴趣的同学可以去看看(www.bookingctrip.c ...
- Opencv各版本的配置
OpenCV 2.49 + VS2012 配置指南 首先下载 OpenCV2.4.9 源码: 一. 配置系统环境变量 1. 将源码解压到指定目录: 2. 将 opencv 添加到系统环境变量: ...
- IntelliJ IDEA部署tomcat时Edit Configuration无artifact选项
IntelliJ使用 ##使用IntelliJ IDEA配置web项目时,选择Edit Configration部署Tomcat的Deployment可能会出现以下情况: 导致新手部署过程中摸不着头脑 ...
- mysql官网文档调试MYSQL资料 5.7
http://dev.mysql.com/doc/refman/5.7/en/debugging-server.html
- authentication not supported Connect to TFS Git from Xamarin Studio (non-hosted, locally installed TFS 2013)
There are several instructions on how to connect to TFS Git from Xamarin Studio if you're using the ...