Digital Roots(hdoj1013)
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.
integers, one per line. The end of the input will be indicated by an integer
value of zero.
on a separate line of the output.
#include<stdio.h>
#include<string.h>
int s(int sum)
{
int a=,b=;
while(sum!=)
{
a=sum%;
sum=sum/;
b+=a;
}
return b;
}
int main()
{
char a[];
int len;
while(gets(a)&&a[]!='')
{
int sum=;
len=strlen(a);
while(len--)
{
sum+=a[len]-'';
}
while(sum>=)
sum=s(sum);
printf("%d\n",sum);
}
}
WAcode:
#include<stdio.h>/*原因貌似是因为位数不够。。*/
int main()
{
int n;
while(scanf("%d",&n)==&&n!=)
{
while(n>=)
{
n=n/+n%;
}
printf("%d\n",n);
}
}
Digital Roots(hdoj1013)的更多相关文章
- HDOJ 1163 Eddy's digital Roots(九余数定理的应用)
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
- HDU 1013 Digital Roots(字符串,大数,九余数定理)
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU——1163Eddy's digital Roots(九余数定理+同余定理)
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- Eddy's digital Roots(九余数定理)
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU-1163 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(to_string的具体运用)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1013 Digital Roots Time Limit: 2000/1000 MS (Java/Othe ...
- 数字色彩的艺术 | The Art Of Digital Color(修订)
翻译一篇来自2011年的文章,原链地址:https://www.fxguide.com/featured/the-art-of-digital-color/ 在这个时期,DPX日渐式微,ACES方兴未 ...
- poj 1284 Primitive Roots (原根)
Primitive Roots http://poj.org/problem?id=1284 Time Limit: 1000MS Memory Limit: 10000K Descr ...
- hdu--1013--Digital Roots(字符串)
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
随机推荐
- javascript统计输入文本的简易方法
计算文本框的输入字符数的简易方法: ]; var tValue = text.value; num = Math.ceil(getLength(tValue)/); //正则:用于区分中文为两个字节 ...
- mysql索引分类及注意事项
MYSQL索引主要分为四类:主键索引,普通索引(聚合,非聚合),唯一索引,全文索引 全文索引,主要是针对对文件,文本的检索, 比如文章, 全文索引针对MyISAM有用. 索引的原理:利用二叉树(哈希表 ...
- NASM mode for Emacs
NASM mode for Emacs Quick post for those Emacs users out there. The common assembler used on GNU ...
- 大规模集群FTP代理(基于lvs的vsftpd网络负载均衡方案部署(PASV))
[目的] 在日常工作中,我们经常需要在某服务器上开FTP(Server)服务.但就是这么简单的事情通常也会变得很复杂,原因如下:1.需要开通FTP的服务器没有公网IP地址:(即不能直接访问到)2.这样 ...
- 华为IC设计人员的薪酬(5年经验28万),以及麒麟是如何脱颖而出的~
垂直整合助力麒麟腾飞 由于ARM技术路线大幅降低了技术门槛和研发的资金和时间成本,导致ARM阵营参与者众多,加上大家都是购买ARM的CPU核与GPU核,造成产品高度同质化,市场竞争异常激烈——在价格上 ...
- CSS之清除浮动
一.清除浮动的目的. 1.当一个父元素的高度不写或为auto时,而且这个父元素内又有浮动的子元素,那么这时候该父元素的高度将不会自动适应子元素的高度,也可以说高度是0px; 有如下代码: <di ...
- 【POJ 2010 Moo University-Financial Aid】优先级队列
题目链接:http://poj.org/problem?id=2010 题意:C只牛犊,各有自己的分数score和申请的补助aid,现要选出N只(N为奇数),使得其aid的总和不超过F,且按score ...
- 【错误】:Could not open JDBC Connection for transaction; nested exception is: Communications link failure;The last packet sent successfully to the server was 1 milliseconds ago
# #错误日志 2016-11-10 16:19:20,834 ERROR [org.quartz.core.JobRunShell] - Job DEFAULT.jobtask threw an u ...
- 认识Junit
JUnit是一个Java语言的单元测试框架.它由Kent Beck和Erich Gamma建立,逐渐成为源于Kent Beck的sUnit的xUnit家族中最为成功的一个. JUnit有它自己的JUn ...
- 关于《平安iOS面试》小结
面了下平安好医生iOS职位,结果不是很理想,也就是GG.写此文的目的在于,时刻提醒自己应该学到老,不要安于现状.也给那些以后去面试的coder一些"剧透"! 一.第一轮 妹子 面试 ...