Digital Roots

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

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
 
Source
分析:很智障的题,我当时一直在想这怎么处理数字问题,没考虑这输入数字无限大的问题,sb啊,直接字符串从低到高位搞一下就好了,每一位处理即可!
下面给出AC代码:
 #include <bits/stdc++.h>
using namespace std;
int main()
{
string str;
while(cin>>str&&str!="")
{
int num=;
for(int i=;i<str.length();i++)
{
num+=str[i]-'';
if(num>)
num=num/+num%;
}
cout<<num<<endl;
}
return ;
}

HDU 1013 Digital Roots【字符串,水】的更多相关文章

  1. HDU 1013 Digital Roots(字符串)

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

  2. HDU 1013 Digital Roots(to_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【模拟或数论】【8月16】

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

  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. Jmeter中java.net.URISyntaxException错误

    今天在做服务发布性能测试的时候,傻傻的犯了个错,没有对参数进行仔细的检查,直接从fiddler中copy到jmeter中了,业务流程配置好后执行测试报错... jmeter中的响应结果如下: java ...

  2. crm踩坑记(三)

    React 如何同步更新state 由于setState方法是异步的,而通常很多时候在一个生命周期里更新state后需要在另一个生命周期里使用这个state. 下面介绍几个方法 // 1 this.s ...

  3. 小白的Python之路 day4 json and pickle数据标准序列化

    一.简述 我们在写入文件中的数据,只能是字符串或者二进制,但是要传入文件的数据不一定全是字符串或者二进制,那还要进行繁琐的转换,然后再读取的时候,还要再转回去,显得很麻烦,今天就来学习标准的序列化:j ...

  4. Linux目录结构详解

    /: 根目录,一般根目录下只存放目录,不要存放文件,/etc./bin./dev./lib./sbin应该和根目录放置在一个分区中/bin:/usr/bin: 可执行二进制文件的目录,如常用的命令ls ...

  5. ADB 安卓开发配置环境

    下载完后将名称中含有adb的文件,和fastboot.exe复制到 c:/windows/system32目录 或c:/windows/system64目录(看自己电脑系统配置 如电脑64操作系统就写 ...

  6. WebSocket协议:5分钟从入门到精通

    一.内容概览 WebSocket的出现,使得浏览器具备了实时双向通信的能力.本文由浅入深,介绍了WebSocket如何建立连接.交换数据的细节,以及数据帧的格式.此外,还简要介绍了针对WebSocke ...

  7. C# DataGridView 的UserDeletingRow事件,删除

    DialogResult dr = MessageBox.Show("确认删除记录吗?", "提示", MessageBoxButtons.YesNo);    ...

  8. 适合小白/外行的git与github最基础最浅显教程

    首先声明,这是适合小白/外行/初学者/学生看的最基础最简单的git与github教程,已经能使用svn,git等工具的朋友请不要看这篇文章来浪费时间了. 想进一步学习git的,推荐去廖雪峰博客学习. ...

  9. vue2 3d 切换器

    空闲时写了一个3d切换器,灵感来自于转行前画3d工程图,效果如图: 功能:按住鼠标中间,变为3d模式,点击6个页面中的某一个页面,页面旋转放大,恢复到2d图形,3d图消失.再次点击鼠标中间,恢复为3d ...

  10. golang 最和谐的子序列

    We define a harmonious array is an array where the difference between its maximum value and its mini ...