传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1013

Digital Roots

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

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
0
 
Sample Output
6
3
 
 
分析:
这个题有点坑,不能用int输入,也不能用long long 输入
得用字符串
应该是输入太大了
有点编译器可能无法识别to_string,需要下载补丁。。。
比如codeblocks
code:
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
typedef long long LL;
int main()
{
string s;
LL sum;
while(cin>>s)
{
if(s=="")
break;
while(s.size()>)//当size==1的时候,就是答案
{
sum=;
for(int i=;i<s.size();i++)
{
sum+=(s[i]-'');//累加
}
s=to_string(sum);//转化成字符串
}
cout<<s<<endl;
}
return ;
}

HDU 1013 Digital Roots(to_string的具体运用)的更多相关文章

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

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

  2. HDU 1013 Digital Roots(字符串)

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

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

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

  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 Digital Roots 题解

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

  6. hdu 1013 Digital Roots

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

  7. HDU OJ Digital Roots 题目1013

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

  8. HDU - 1310 - Digital Roots

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

  9. 杭电 1013 Digital Roots

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

随机推荐

  1. js实现数组内数据的上移和下移

    var swapItems = function(arr, index1, index2){ arr[index1] = arr.splice(index2,1,arr[index1])[0] ret ...

  2. Python基础-列表生成式和生成器表达式

    一.列表生成式(List Comprehension) 列表生成式即List Comprehensions,是Python内置的非常简单却强大的可以用来创建list的生成式. 举个例子,要生成list ...

  3. mysql的一些sql用法

    mysql中修改列名: alter table 表名 change abc def 列类型;比如 alter table student change pws psw char(10);

  4. maoaolianxi

    package dududu; public class maopao { public static void main(String[] args) { // TODO 自动生成的方法存根 ,,, ...

  5. python numpy+mkl+scipy win64 安装

    用pip在windows下安装numpy,scipy等库时一般来说都不会很顺利比较好的方式是自己下载对应的whl文件pip install 话不多说上链接 http://www.lfd.uci.edu ...

  6. 搭建git远程仓库

    基于本地协议搭建git远程仓库 1.任意目录下执行git init -bare创建裸仓库,建议目录名称以.git结尾 2.共享此目录,windows下右键裸仓库目录,切换到共享面板设置完成即可获取共享 ...

  7. 深入理解token

      链接:https://my.oschina.net/jamesfancy/blog/1613994 摘要: Token 是在服务端产生的.如果前端使用用户名/密码向服务端请求认证,服务端认证成功, ...

  8. C#启动服务

    启动服务的方法有很多种,简单的cmd下dos命名,手动启动,还有C#代码启动. 我们要实现的功能: 判断是否安装 是否启动 启动服务 关闭服务 我封装了有关服务的代码,如下: using System ...

  9. easyui datagrid行编辑中数据联动

    easyui的datagrid中行内编辑使用数据联动.即:当编辑产品编号时,该行的产品名称自动根据产品编号显示出来. 在编辑中获取当前行的索引 function getRowIndex(target) ...

  10. lua的面向对象实现

    百度搜索一下,给出出的解决方案和学习帖子很多,可是我还是有很多的问题! (1)什么是面向对象? (2)lua中怎么实现面向对象? (3)什么样的实现既简单又能完成我的功能? (4)一定要按照c++的方 ...