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 ...
随机推荐
- Laravel 数据库实例教程 —— 使用DB门面操作数据库
Laravel支持多种数据库,包括MySQL.Postgres.SQLite和SQL Server,在Laravel中连接数据库和查询数据库都非常简单,我们可以使用多种方式与数据库进行交互,包括原生S ...
- 查看/设置MySQL数据库的事务隔离级别
查看InnoDB存储引擎 系统级的隔离级别 和 会话级的隔离级别: mysql> select @@global.tx_isolation,@@tx_isolation; +---------- ...
- poj 2553 The Bottom of a Graph(强连通、缩点、出入度)
题意:给出一个有向图G,寻找所有的sink点.“sink”的定义为:{v∈V|∀w∈V:(v→w)⇒(w→v)},对于一个点v,所有能到达的所有节点w,都能够回到v,这样的点v称为sink. 分析:由 ...
- 自己定义popupwindow二三事
效果图: 代码: public class ViewActivity extends Activity implements View.OnClickListener { PopupWindow po ...
- 第3章 如何编写函数定义 3.7 if特殊表
这部分来学习下if特殊表,之前学了defun和let,不好意思,博客中没有写但是鄙人已经看了,哈哈. 什么是if表 if条件特殊表是为了让计算机对条件加以判断,然后选择不同的执行路径的. if特殊表的 ...
- 使用javac,手动编译一个java文件的方法
参考<Tomcat与Java Web开发技术详解>中的命令: javac -classpath c:\tomcat\lib\servlet-api.jar ...
- NOJ1167 丑陋数 想法题
题意 丑陋数n的意思是n的全部素数因子仅仅有2,3,5. 求出前1500个丑陋数. (第一个丑陋数是1) 思路 用一个数组维护全部的丑陋数. 一開始数组中仅仅有一个数就是1. 如今能够确定的丑陋数还有 ...
- Mysql----mysql启动服务时提示"服务名无效"
1,首先说明一下我的环境,我刚开始是用的XAMPP这个集成的软件,里面安装了apache, mysql,tomcat这些软件,然后通过控制面板对其进行启动关闭的操作,这些操作很方便,但是我就用net ...
- Spring 和 filter
标题是 spring和filter,但是这里却是说的spring MVC 项目中需要用到filter,filter中需要用到spring实例化的bean,于是为了简化就形成spring和filter了 ...
- 【BZOJ4542】[Hnoi2016]大数 莫队
[BZOJ4542][Hnoi2016]大数 Description 小 B 有一个很大的数 S,长度达到了 N 位:这个数可以看成是一个串,它可能有前导 0,例如00009312345.小B还有一个 ...