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: ...
随机推荐
- 关于Spring中的PagedListHolder分页类的分析
PagedListHolder 这个类可以 对分页操作进行封装 文件在:import org.springframework.beans.support.PagedListHolder;下 默认是把查 ...
- Struts2小结
Struts 2是在WebWork2基础发展而来的. 注意:struts 2和struts 1在代码风格上几乎不一样. Struts 2 相比Struts 1的优点: 1.在软件设计上Struts 2 ...
- select与epoll分析
关于select与epoll的区别,网上的文章已是一大堆.不过别人的终究是别人的,总得自己去理解才更深刻.于是在阅读了大量的文章后,再装模作样的看下源码,写下了自己的一些理解. 在开始之前,要明白li ...
- 软件project(五)——可行性研究
一.目的 用最小的代价高效率的确定问题是否可以解决. 不是去解决这个问题,而是确定问题是否值得去解决.进行可行性研究简化了系统分析和系统设计的过程. 二.任务 (1)进一步分析问题定义. (2)分析员 ...
- read(),write() 读/写文件
read read()是一个系统调用函数.用来从一个文件中,读取指定长度的数据到 buf 中. 使用read()时需要包含的头文件: <unistd.h> 函数原型: ssize_t re ...
- mount USB Device(U disk) on crux based on vmware
1. 在 /mnt 下建立一个名叫USB的文件夹,文件夹名自定 cd /mnt mkdir USB 2. 查看一下磁盘分区情况 fdisk –l 3. 插入U盘 4. 再次查看磁盘分区情况,对比第一次 ...
- Java第三周学习日记
Day01 1.线程 进程:进程就是正在运行的应用程序.进程负责了内存空间的划分. 线程:一个进程中的代码是由线程去执行的,线程也就是其中一个执行路径. 多线程:一个进程中有多个线程可以同时执行任务. ...
- Hacker(24)----防范密码被轻易破解
无论什么类型密码,用户在设置时都有非常小心,防止自己设置的密码被他人轻易破解.为保护重要的文件和资料,可采用加密工具进行加密,即可选择Win7系统自带的BitLocker,也可使用Internet中很 ...
- 《第一行代码》学习笔记17-碎片Fragment(2)
1.碎片的状态和回调: (1)运行状态:碎片可见+所关联的活动处于运行状态. (2)暂停状态:当活动进入暂停状态(由于另一个未占满屏幕的活动被添加到栈顶),与其相关联的可见碎片会进入暂停状态. (3) ...
- sql语句的分类
这些天在看Oracle database 11g SQL开发指南,关于sql语句的分类,感觉有必要记录一下. sql语句主要分五类: DML(DATA MANIPULATION LANGUAGE, 数 ...