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的更多相关文章

  1. HDU 1013 Digital Roots(to_string的具体运用)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1013 Digital Roots Time Limit: 2000/1000 MS (Java/Othe ...

  2. HDU 1013 Digital Roots【字符串,水】

    Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  3. HDU 1013 Digital Roots(字符串)

    Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...

  4. HDU 1013.Digital Roots【模拟或数论】【8月16】

    Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...

  5. HDU 1013 Digital Roots(字符串,大数,九余数定理)

    Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. 杭电 1013 Digital Roots

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1013 反思:思路很简单,但是注意各位数加起来等于10的情况以及输入0的时候结束程序该怎么去表达 #in ...

  7. HDU 1013 Digital Roots 题解

    Problem Description The digital root of a positive integer is found by summing the digits of the int ...

  8. hdu 1013 Digital Roots

    #include <stdio.h> int main(void) { int m,i;char n[10000]; while(scanf("%s",&n)= ...

  9. Problem : 1013 ( Digital Roots )

    tips:分析不够仔细,白费了许多功夫.输入数据的范围,平时几乎很少考虑的,这个以后得注意.代码检查不够仔细啊,以后得注意了 #include<iostream> using namesp ...

  10. 解题报告:hdu1013 Digital Roots

    2017-09-07 22:02:01 writer:pprp 简单的水题,但是需要对最初的部分进行处理,防止溢出 /* @theme: hdu 1013 Digital roots @writer: ...

随机推荐

  1. window.open和window.close的使用详解

    有时候,我们想通过JS实现一个<a>的新开标签的效果,此时我们想到了window.open方法实现.那么window.open到底应该怎么使用呢?   我们知道window.open可以新 ...

  2. maven编写主代码与测试代码

    3.2 编写主代码 项目主代码和测试代码不同,项目的主代码会被打包到最终的构件中(比如jar),而测试代码只在运行测试时用到,不会被打包.默认情况下,Maven假设项目主代码位于src/main/ja ...

  3. python在一个列表中查找

    # -*- coding: utf-8 -*-__author__ = 'Administrator'import bisect#简化一些操作#1:在一个列表中查找""" ...

  4. banner背景通栏

     background: #76CEF6 url("../images/bg.jpg") repeat-x 0 0;  -webkit-background-size: 100%; ...

  5. html li标签前面添加图标三种方法

    今天无聊写下这个例子,希望对初学者有帮助,代码如下 <!DOCTYPE html> <html> <head> <meta charset="utf ...

  6. input文本框获取焦点和失去焦点判断

    onBlur:当输入框失去焦点后 onFocus:当输入框获得焦点后 这两个JavaScript事件是写在html标签中的例如: <input type="text" onB ...

  7. THINKPHP之控制器

    如何新增控制器? 在Lib/Action中新增一个控制器:ProductAction.class.php: <?php class ProductAction extends Action{   ...

  8. spark 高级算子

      mapPartitionsWithIndex val func = (index: Int, iter: Iterator[(Int)]) => {   iter.toList.map(x  ...

  9. RAC 的一些概念性和原理性的知识(转)

    一 集群环境下的一些特殊问题 1.1 并发控制 在集群环境中, 关键数据通常是共享存放的,比如放在共享磁盘上. 而各个节点的对数据有相同的访问权限, 这时就必须有某种机制能够控制节点对数据的访问. O ...

  10. ie8 hack

    1.‘\9’: eg:.test { color/*\**/: blue\9 }.header {width:300px;} /* 所有浏览器*/.header {width/*\**/:330px\ ...