HDOJ-1013 Digital Roots
http://acm.hdu.edu.cn/showproblem.php?pid=1013
1.给出一个整数,求每一位上的数字之和
2.若求出的和大于1位,则对该和继续执行第1步,直至和的位数为1
注意:该整数有可能远远大于int或__int64的取值范围,所以用字符数组处理
# include <stdio.h>
# include <string.h> int main()
{
char num[100000], i;//输入整数长度可能远远超过整数范围 while(scanf("%s",num) && strcmp(num, "0"))
{
int temp = 0;
for(int i = 0; num[i] != '\0'; i++)//第一次对输入的整数求位和
temp += num[i] - '0'; while(temp >= 10)//若位和的位数大于1位 重复求位和操作
{
int t = temp;
temp = 0;
while(t > 0)
{
temp += t % 10;
t = t / 10;
}
}
printf("%d\n",temp);
} return 0;
}
HDOJ-1013 Digital Roots的更多相关文章
- HDU 1013 Digital Roots(to_string的具体运用)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1013 Digital Roots Time Limit: 2000/1000 MS (Java/Othe ...
- HDU 1013 Digital Roots【字符串,水】
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1013 Digital Roots(字符串)
Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...
- HDU 1013.Digital Roots【模拟或数论】【8月16】
Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...
- HDU 1013 Digital Roots(字符串,大数,九余数定理)
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 杭电 1013 Digital Roots
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1013 反思:思路很简单,但是注意各位数加起来等于10的情况以及输入0的时候结束程序该怎么去表达 #in ...
- HDU 1013 Digital Roots 题解
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
- hdu 1013 Digital Roots
#include <stdio.h> int main(void) { int m,i;char n[10000]; while(scanf("%s",&n)= ...
- Problem : 1013 ( Digital Roots )
tips:分析不够仔细,白费了许多功夫.输入数据的范围,平时几乎很少考虑的,这个以后得注意.代码检查不够仔细啊,以后得注意了 #include<iostream> using namesp ...
- 解题报告:hdu1013 Digital Roots
2017-09-07 22:02:01 writer:pprp 简单的水题,但是需要对最初的部分进行处理,防止溢出 /* @theme: hdu 1013 Digital roots @writer: ...
随机推荐
- (step5.1.6)hdu 1272(小希的迷宫——并查集)
题目大意:输入一系列的点,判断这些点组成的图符不符合小希的思路(无环.连通) 解题思路: 1)如果两个节点的根节点相同,那么在这两个节点之间添加1条边以后,这个图肯定有环路. 2)孤立节点:被使用过& ...
- java多个listener监听
java 多个listener 监听方法 在class 名称上一行添加@Listeners 括号中用逗号隔开 @Listeners({com.example.MyListener.class,com. ...
- Eclipse调试时出现source not found的问题
Eclipse中新加载了一个java项目,打断点debug时,Debug小窗口显示source not found,网搜找到了解决办法,在此记录一下. 原文地址:http://blog.csdn.ne ...
- 并行计算基础&编程模型与工具
在当前计算机应用中,对快速并行计算的需求是广泛的,归纳起来,主要有三种类型的应用需求: 计算密集(Computer-Intensive)型应用,如大型科学project计算与数值模拟: 数据密集(Da ...
- Eclipse 将projectBuild Path中引用的jar包自己主动复制到WEB-INF下的lib目录下
在用用 Eclipse进行Java Web开发时,web应用中引用的jar须要复制到WEB-INF下的lib目录下,否则常常出现ClassNotFound异常. 通过以下方法,能够不用手动拷贝jar包 ...
- c#基础: 线程的初级用法总结
启动一个线程的两种方法: a.使用无参的方法 Thread thread1 = new Thread(new ThreadStart("调用的方法名")): ...
- let关键字
作用: 与var类似, 用于声明一个变量特点: 只在块作用域内有效 不能重复声明 不会预处理, 不存在提升应用: 循环遍历加监听 //应用实例 <body> <button>测 ...
- 未能的导入项目,请确认<Import>声明中的路径正确
对于这样的错误,根据提示应该是项目的管理文件(.csproj)中有问题.找到对应的位置修改即可
- CSS 设计模式一 元素
1.background 内置 是一种CSS内置设计模式,支持在元素下显示图片 HTML <!DOCTYPE html> <html lang="en"> ...
- nginx和apache的特点优点和使用场景
Apache Apache是世界使用排名第一的Web服务器软件.它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一. Apache源于 ...