传送门: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. weblogic11g(10.3.6)部署war包时,解决jar包冲突的超简方案

    亲测有效:weblogic11g(10.3.6) + jdk7,打包使用jdk7或jdk8,注意weblogic用的jdk和打包时jdk的兼容. 分别配置web项目下pom.xml和weblogic. ...

  2. RabbitMQ基础--总结

    一. RabbitMQ的五种工作场景: 1. 单发单收 2. 单发送多接收 +++++++++++++++++++++前面两种没有使用exchange++++++++++++++++++ 3. Pub ...

  3. 初学者需要IPython 与 Jupyter Notebook 吗?

    ipython 是 jupyter notebook的前身并拥有ipython的全部功能         jupyter拥有 cell, markdown 整合的功能, 能同时运行代码, 而且是多组的 ...

  4. Windows 64位下安装Redis教程

    Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型. Key-Value数据库,并提供多种语言的API. 一.下载 地址:Download redis-latest ...

  5. 日常捕获的野生知识 - javascript获取屏幕大小

    刚刚接触JavaScript,涉及到 document , window 的一些基本知识不是很了解,今天为了一个屏幕大小折腾了半天,幸好找到了很好的例子学习. 代码如下: <html> & ...

  6. 命令解决500 Error: Cannot find module 'XXX'

    装express之后访问http://localhost:3000.会出现500 Error: Cannot find module 'xxx'错误 解决方案: 确定package.json里有添加相 ...

  7. 提问的智慧 How To Ask Questions The Smart Way

    提问的智慧 How To Ask Questions The Smart Way Copyright © 2001,2006,2014 Eric S. Raymond, Rick Moen 本指南英文 ...

  8. Jmeter参数化设置,多用户登录

    一.模拟多用户登录场景 如登录模式如下图所示,登录界面中需要输入:用户名.密码.验证码 用户名以及密码均是固定值,不需要做处理.验证码需要处理一下,可以后台配置成固定值,具体可以找开发咨询. 在此场景 ...

  9. C++ 11: function & bind 使用示例

    #include <functional> #include <iostream> struct Foo { Foo(int num) : num_(num) {} void ...

  10. Ubuntu下安装CUDA

    cuda check: cuDNN 下载cuDNN后解压 更新软链接 更新链接库 symbol link 参考链接: http://docs.nvidia.com/cuda/cuda-installa ...