题目的链接为:
http://acm.njupt.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1028
题目为:
Digital Roots
时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte
总提交:329 测试通过:112
描述
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.
输入
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.
输出
For each integer in the input, output its digital root on a separate line of the output.
样例输入
24
39
0
样例输出
6
3
题意就不写了,是个人就看得明白。重点是,这本身一道极其水的题目,却在我没有考虑输入的数字可能无限大的情况下,硬是WA了N次。我都佩服我自己了....考虑问题居然这样不经过大脑。
#include<iostream>
using namespace std;
int main(){
string str;
while(cin>>str&&str!="0"){
int num=0;
for(int i=0;i<str.length();i++){
num+=str[i]-'0';
if(num>9){
num=num/10+num%10;
}
}
cout<<num<<endl;
}
system("pause");
return 0;
}
分享到:
相关推荐
1115 Digital Roots 简单题 1113 u Calculate e 简单题 1152 A Mathematical Curiosity 简单题 1154 Niven Numbers 简单题 1160 Biorhythms 简单题 1163 The Staircases 简单题 1177 K-Magic Number ...
1115 Digital Roots 简单题 1113 u Calculate e 简单题 1152 A Mathematical Curiosity 简单题 1154 Niven Numbers 简单题 1160 Biorhythms 简单题 1163 The Staircases 简单题 1177 K-Magic Number ...
reasons: to limit the length of the paper and because methods dealing with roots, seeds and fruits have some peculiarities that would warrant a specific survey. The selected proposals are divided into...
The roots of an arbitrary function or equation are calculated
roots, 快速高级前端开发工具包 根是一个快速。简单且可以定制的static 站点编译器。它不在积极开发中,也不会增加新特性。 根团队现在正在处理 spike,它已经匹配和取代了根的capabilities 。 我们鼓励你在开始新...
《ROOTS品牌管理方法论白皮书》.pdf
roots-example-project.com, 根堆栈工程( 格,基岩,Sage ) 根示例项目这里知识库是如何集成和使用以下项目的一个示例:基岩网格Sage ( 带土壤的)有关...这个项目是一个完整的工作示例,部署在 Digital Ocean 512MB dro
Computing Roots of Polynomials ,采用数值方法求根,速度快,很好
roots of quatratic eq
Roots_uniqe.m
Roots最吸引人的地方是它清理了很多wordpress相关的东西,这样你可以花更多的时间来写代码而不是处理WordPress的设置。 用户可以移除bootstrap用其他CSS框架代替。支持多种语言(Brazilian Portuguese, Bulgarian, ...
Polynomial Root Finder is a reliable and fast C program (+ Matlab gateway) for finding all roots of a complex polynomial.
求一元二次方程ax2 + bx + c = 0 的根,不管它的根是实根还是复根,有一个根还是两个根。
fixed point iteration for finding roots
poj 1284 Primitive Roots.md
fileSystems-roots.js
Roots_exist1.m
自动部署 WordPress 和 Roots 对于本地 Ubuntu 14.04 开发环境。 需要 。 注意:我对 BASH 脚本很陌生,所以请仔细阅读此代码。 它对我们很有效,但使用风险自负! ##它能做什么## 在/var/www为站点创建一个新...
Mathematics Numerical Algorithms using matlab code
Functional roots of the sine function