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 ...
随机推荐
- 计算机网络11--OSI參考模型
本页内容 1.OSI參考模型简单介绍 2.OSI參考模型通信过程 3.OSI參考模型的数据封装 4.数据封装的意义 5.物理层 6.数据链路层 7.网络层 8.传输层 9.会话层 10.表示层 11. ...
- 人不在囧途 便携式3G上网设备+套餐推介
来源: http://network.pconline.com.cn/317/3174920_all.html [PConline资讯]过年回家,本该是再高兴不过的事,可一想到要在路上颠簸数十个小时, ...
- 利用nginx搭建tomcat集群
1.tomcat集群 利用nginx对请求进行分流,将请求平均的分给不同的tomcat去处理,减少单个tomcat的负载量,提高tomcat的响应速度. 2.创建多个tomcat服务器(同一个服务器上 ...
- Proftp设置虚拟用户(转)
首先在proftpd.conf中添加: AuthOrder mod_auth_file.c mod_auth_unix.c AuthUserFile /usr/local/etc/ftp ...
- java中双向链表的增、删、查操作
import java.util.NoSuchElementException; public class DoublyLinkedListImpl<E> { private Node h ...
- "fcitx按ctrl+space没反应"解决方法
如果是KDM.GDM.LightDM,打开~/.xprofile.如果是startx.Slim,打开~/.xinitrc.(没有就新建一个) export GTK_IM_MODULE=fcitxexp ...
- kill 命令
Linux中的kill命令用来终止指定的进程(terminate a process)的运行,是Linux下进程管理的常用命令.通常,终止一个前台进程可以使用Ctrl+C键,但是,对于一个后台进程就须 ...
- sublime使用技巧(1)-- 下载与插件安装
一.下载 到官网下载最新的版本 https://www.sublimetext.com/ Sublime官方插件网站 https://packagecontrol.io/ 二.插件安装配置 1.打开S ...
- java中什么是bridge method(桥接方法)
java中什么是bridge method(桥接方法) https://blog.csdn.net/z69183787/article/details/81115524
- 做完task1-21的阶段总结
[说明]这是自注册修真院的第七天,也是第七篇日报,觉得是一个好的时机总结一下. 因为任务一虽然看起来仅仅是“完成学员报名的DB设计并读写数据库”,但是做了几天之后就发现在任务“搭建自己的服务器”之前的 ...