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 ...
随机推荐
- ZendFramework 两种安装方式
1. 在线安装(基于composer) Zend 应用程序骨架 GitHub 地址: https://github.com/zendframework/ZendSkeletonApplication ...
- NAS4Free 安装配置 -- 目录
淘了个DIY的NAS主机,装了3块硬盘,安装配置NAS4Free,用来存储照片.电影等资料,并兼做下载机. 现在把拆箱.安装.配置过程记录下来,供有兴趣的同学参考. NAS4Free 安装配置(一)开 ...
- Bone Collector II(HDU 2639 DP)
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- Hdu1001(1到100的和)
常规算法: #include <stdio.h> int main() { // 常规算法 int a; while(scanf("%d",&a)!=EOF){ ...
- Ring3下Hook NtQueryDirectoryFile隐藏文件
NTSTATUS WINAPI Hook_NtQueryDirectoryFile(IN HANDLE FileHandle,IN HANDLE Event OPTIONAL,IN PIO_APC_R ...
- windows phone中,将crash report记录下来,写入文件,方便分析
APP出现crash(崩溃)总是不能忍的 当我们连接调试器调试的时候,发现每当APP崩溃的时候 程序都会走到App.xaml.cs中的 // Code to execute on Unhandled ...
- Android 操作系统的内存回收机制[转]
转自:http://www.ibm.com/developerworks/cn/opensource/os-cn-android-mmry-rcycl/ Android APP 的运行环境 Andro ...
- 剑指offer-面试题12.打印1到最大的n位数
题目:输入数字n,按照打印出从1最大的n位10进制数.比如3,则 打印出1.2.3一直到最大的3位数即999 1.你觉得如果面试会有这么简单的题,那 只能说明你---太天真. 2.n=3尚可,如果n= ...
- OpenWrt 学习网址
http://m.blog.csdn.net/blog/woods2001/8137755
- 不重启mysqld更改root密码
Ever found yourself working on a MySQL server where root’s password is unavailable? It has happened ...