SDUT 1048 Digital Roots
Digital Roots
Time Limit: 1000ms Memory limit: 65536K
题目描述
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.
输入
positive integers, one per line. The end of the input will be indicated
by an integer value of zero.
输出
示例输入
24
39
0
示例输出
6
3
提示
#include <stdio.h>
#include <string.h> int main()
{
char s[50];
int a[50], e;
int i, j, k;
int sum;
while(scanf("%s", s)!=EOF )
{
if(s[0]=='0')
break;
int len=strlen(s);
e=0;
sum=0;
for(i=0; i<len; i++)
{
a[e++]=s[i]-48 ;
sum+=a[e-1];
}
if(sum<10)
printf("%d\n", sum );
else
{
int cnt=sum;
sum=0;
while(cnt>10)
{
while(cnt!=0)
{
sum=sum + (cnt%10);
cnt=cnt/10;
}
if(sum<10)
{
printf("%d\n", sum );
break;
}
else
{
cnt=sum;
sum=0;
}
}
}
}
return 0;
}
SDUT 1048 Digital Roots的更多相关文章
- Digital Roots 1013
Digital Roots 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交:456 测试通过:162 描述 T ...
- Eddy's digital Roots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- Digital Roots 分类: HDU 2015-06-19 22:56 13人阅读 评论(0) 收藏
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- HDU 1163 Eddy's digital Roots
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- ACM——Digital Roots
http://acm.njupt.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1028 Digital Roots 时间 ...
- HDOJ 1163 Eddy's digital Roots(九余数定理的应用)
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
- Eddy's digital Roots(九余数定理)
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU1163 Eddy's digital Roots【九剩余定理】
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU 1013 Digital Roots(字符串)
Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...
随机推荐
- 转 RabbitMQ
转自:https://blog.thankbabe.com/2017/08/03/rabbitmq-demo/?from=cnblogs 介绍 RabbitMQ是一个由erlang开发的基于AMQP( ...
- CentOS修改IP地址及关闭/打开防火墙
1.CentOS修改IP地址: # ifconfig eth0 192.168.1.80 这样就把IP地址修改为192.168.1.80(如果发现上不了网 了,那么你可能需要把网关和DNS也改一下,后 ...
- oracle查询当前会话数量
SELECT a.inst_id,sid,username,event,sql_id,a.PROGRAM FROM gv$session a WHERE a.STATUS='ACTIVE' AND u ...
- [译]GLUT教程 - 修改菜单
Lighthouse3d.com >> GLUT Tutorial >> Pop-up Menus >> Modifying Menus 肯定会有菜单需要被修改的状 ...
- MyBatis随笔
前一阵参与了一个项目的搭建,为了快速开发再加上学一些新东西,准备采用React+Spring MVC+MyBatis的架构. 花了一些时间最终把Spring MVC+MyBatis打通. 这里总结下M ...
- erlang实现一个进程池 pool
erlang的实现一个简单的进程池. erlang进程是非常轻量级的,这个进程池的主要目的是用一种通用的方式去管理和限制系统中运行的资源占用.当运行的工作者进程数量达到上限,进程池还可以把任务放到队列 ...
- 【转】Jenkins+Ant+Jmeter接口自动化集成测试实例
出处:https://my.oschina.net/MrToStudy/blog/742251 一.Jenkins安装配置 1.安装配置JDK1.6+环境变量: 2.下载jenkins.war,放入C ...
- PHP-Manual的学习----【语言参考】----【类型】-----【Resource 资源类型】
2017年8月24日11:29:361.资源 resource 是一种特殊变量,保存了到外部资源的一个引用.资源是通过专门的函数来建立和使用的.2.由于资源类型变量保存有为打开文件.数据库连接.图形画 ...
- java基础之【堆、栈、方法区】结构图
|--数组实例化过程 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHViaWFvXzA2MTg=/font/5a6L5L2T/fontsize/400/ ...
- Largest Rectangle in a Histogram (最大子矩阵)
hdu 1506 A histogram is a polygon composed of a sequence of rectangles aligned at a common base line ...