hdu--1013--Digital Roots(字符串)

时间:2021-09-19 20:33:22

Digital Roots

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 77503    Accepted Submission(s): 24224

Problem Description
The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is continued as long as necessary to obtain a single digit.

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.
 
Input
The input file will contain a list of positive integers, one per line. The end of the input will be indicated by an integer value of zero.
 
Output
For each integer in the input, output its digital root on a separate line of the output.
 
Sample Input
24
39
 
Sample Output
6
3
 /*
     Name: hdu--1013--Digital Roots
     Copyright: ©2017 日天大帝
     Author: 日天大帝
     Date: 22/04/17 10:34
     Description: 这个题,就是特别坑
                 如果你一开始把所有的值设置为int型,恭喜你,你会得到一个WA
                 接着你大概会改成unsigned型,恭喜你,你会得到一个超时
                 然后你终于恍然大悟,用字符串!!
 */
 #include<iostream>
 #include<string>
 using namespace std;
 int main(){
     ios::sync_with_stdio(false);

     string str;
     ") {
         ;
         ;
         ){
             int temp = sum;
             sum = ;
             while(temp){
                 sum += temp%;
                 temp /= ;
             }
         }
         cout<<sum<<endl;
     }
     ;
 }

hdu--1013--Digital Roots(字符串)的更多相关文章

  1. HDU 1013 Digital Roots&lpar;字符串&rpar;

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

  2. HDU 1013 Digital Roots(to&lowbar;string的具体运用)

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

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

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

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

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

  5. HDU 1013&period;Digital Roots【模拟或数论】【8月16】

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

  6. HDU 1013 Digital Roots 题解

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

  7. hdu 1013 Digital Roots

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

  8. HDU OJ Digital Roots 题目1013

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

  9. HDU - 1310 - Digital Roots

    先上题目: Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  10. 杭电 1013 Digital Roots

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

随机推荐

  1. &lbrack;Bootstrap&rsqb;7天深入Bootstrap&lpar;1&rpar;入门准备

    由于申请了一个域名,一个云主机,开始弄个人网站. 发现Bootstrap非常方便,和重要,故开始学习与分享关于Bootstrap的技术. 推个广告 个人网站:http://www.neverc.cn ...

  2. 给php增加gd库(转)

    1.安装zlib tar zxvf zlib-1.2.3.tar.gz cd zlib-1.2.3 ./configure --prefix=/usr/local/zlib make make ins ...

  3. Perl内置变量速查表

    [ 文件句柄 ] $| 如果非零, 则在对当前选定的文件执行写或打印操作后强制清除缓冲区 $% 当前选中文件句柄的当前页码 $= 当前选中文件句柄的当前页面长度 $- 当前选中文件句柄的页面剩余长度 ...

  4. Oracle 分析函数 &quot&semi;ORA-30485&colon; 在窗口说明中丢失 ORDER BY 表达式&quot&semi;

    跟顺序有关的几个分析函数row_number.rank.dense_rank.lead和lag的over窗口里,都必须有order_by_clause.其他几个如:first_value.last_v ...

  5. Linq中的常用方法

    System.Linq System.Linq.Enumerable  类 Range Repeat Reverse Select Where Sum Zip Aggregate Count Firs ...

  6. The Child and Sequence

    Codeforces Round #250 (Div. 1)D:http://codeforces.com/problemset/problem/438/D 题意:给你一个序列,然后有3种操作 1x ...

  7. Sphinx Makefile

    # Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPT ...

  8. Go-单元测试

        文章转载地址:https://www.flysnow.org/2017/05/16/go-in-action-go-unit-test.html 什么是单元测试?      单元测试一般用来测 ...

  9. B&sol;S架构

    B/S架构即浏览器和服务器架构模式.它是随着Internet技术的兴起,对C/S架构的一种变化或者改进的架构.在这种架构下,用户工作界面是通过WWW浏览器来实现,极少部分事务逻辑在前端(Browser ...

  10. Jmeter - 测试 http 接口

    前言: 本文主要针对http接口进行测试,使用Jmeter工具实现. Jmter工具设计之初是用于做性能测试的,它在实现对各种接口的调用方面已经做的比较成熟,因此,本次直接使用Jmeter工具来完成对 ...