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 ...
随机推荐
- ThinkPhp调用webservice
模板页: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...
- 一级域名301重定向到www二级域名
301重定向有利于百度的搜索 例如一个域名 www.test.com如果不做设置会产生4个网址, (1)test.com(2)www.test.com(3)test.com/default.html( ...
- wine下汉字方块解决
1.修改字体 首先,下载一个字体,例如win下的新宋体 其次, mkdir /usr/share/fonts/windows mv simsun.ttc /usr/share/fonts/window ...
- Python Challenge 过关心得(1)
正式开始第1关,这一关的URL的特殊部分是map. 这关的图片上有一个本子,上面写着K→M,O→Q,E→G,稍微思索就能发现这几个字母都是按照字母表的顺序向后移动了两位,那么最投机取巧的方法就是把ma ...
- Histats安装Counter网站计数器 - Blog透视镜
Histats提供十分多样性的Counter网站计数器,可以依照你个人的喜好与需求,选择适合的Counter网站计数器,也可以针对同一网站,安装多个Counter网站计数器,作法其实比注册账号时更简单 ...
- KEIL CRACK及 0xFD Bug修正方法
0xFD Bug是keil编译器中始终存在,而又从未得到官方修复的一个BUG!!! BUG描述:当C源代码中使用了汉字等非ASCII字符,而此字符的编码又恰好包含了大于或等于0xFD的字节时,这个字节 ...
- Qt5中生成和使用静态库
在QT中静态库的后缀名为.a,在vs中开发的静态库后缀名为.lib.QT版本为5.2.1,系统为Windows. 一. 静态库的生成 新建项目. 新建一个静态库的项目,如图1.1所示:项目名称为tes ...
- GET POST方法长度限制
GET POST方法长度限制 1. Get方法长度限制 Http Get方法提交的数据大小长度并没有限制,HTTP协议规范没有对URL长度进行限制.这个限制是特定的浏览器及服务器对它的限制. ...
- Silverlight 结合ArcGis
原文 http://www.dotblogs.com.tw/justforgood/archive/2012/05/09/72064.aspx 终于有机会谈到ArcGis(觉得很冷门) ,不过既然都做 ...
- 用日志文件备份sqlserver
USE [TestDB] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO )) as ) ),),)),)+ '.bak' backup dat ...