poj 1519 Digital Roots (计算根数字)
一、Description
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
Output
二、题解
本来只用数字操作的,后来发现数字太大了。只能用字符串操作了。
三、java代码
import java.util.Scanner; public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
String s;
int i,sum;
while(true){
s=cin.next();
if(s.charAt(0)==48)
break;
while(true){
sum=0;
for(i=0;i<s.length();i++){
sum+=s.charAt(i)-48;
}
if(0<sum&&sum<=9){
System.out.println(sum);
break;
}else
s="";
s+=sum;
}
}
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
poj 1519 Digital Roots (计算根数字)的更多相关文章
- POJ 1519 Digital Roots
题意:求数根. 解法:一个数的数根就是mod9的值,0换成9,只是没想到给的是一个大数……只好先把每位都加起来再mod9…… 代码: #include<stdio.h> #include& ...
- POJ 1519:Digital Roots
Digital Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25766 Accepted: 8621 De ...
- HDU 1163 Eddy's digital Roots
Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- POJ 1284 Primitive Roots 原根
题目来源:POJ 1284 Primitive Roots 题意:求奇素数的原根数 思路:一个数n是奇素数才有原根 原根数是n-1的欧拉函数 #include <cstdio> const ...
- Digital Roots 1013
Digital Roots 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交:456 测试通过:162 描述 T ...
- Eddy's digital Roots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- Digital Roots 分类: HDU 2015-06-19 22:56 13人阅读 评论(0) 收藏
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- ACM——Digital Roots
http://acm.njupt.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1028 Digital Roots 时间 ...
- HDOJ 1163 Eddy's digital Roots(九余数定理的应用)
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
随机推荐
- 九度OJ 1209:最小邮票数 (遍历)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2252 解决:741 题目描述: 有若干张邮票,要求从中选取最少的邮票张数凑成一个给定的总值. 如,有1分,3分,3分,3分,4分五 ...
- struts2 封装获取表单数据的方式
一.属性封装 1.在action中设置成员变量,变量名与表单中的name属性值相同 2.生成变量的set方法 实例 获取用户输入的用户名和密码 jsp页面 java代码 二.模型驱动(常用) 1.ac ...
- eclipse js调试
问题: js经常会被浏览器给cache,不管怎么刷都是原来的. 解决: 暂时有一个方法,一刷新就好,下面的截图: 1)先打开 <开发者工具> 2)找到Sources 3)Page中找到你的 ...
- eclilpse svn : Item is out of date 解决办法
尝试以下方面, 1. 2.如果上面的还不行,就说明你修改了原有项目结构,可能是增加了新包,或者重命名的包或文件,那么你得先update,然后再提交 这样就OK了,我就是用了2才成功的哦.
- 第2条:遵循PEP8风格指南
<Python Enhancement Proposal #8>(8号Python增强提案)又叫PEP8,它是针对Python代码格式而编订的风格指南. 尽管可以在保证语法正确的前提下随意 ...
- Yii2数据库操作的各种写法
-------------------------------ActiveRecord---------------------------------------- 查询: // find the ...
- Data Structure Binary Search Tree: Find k-th smallest element in BST (Order Statistics in BST)
http://www.geeksforgeeks.org/find-k-th-smallest-element-in-bst-order-statistics-in-bst/ #include < ...
- Android关闭USB的ADB调试和文件传输功能(禁用USB)【转】
本文转载自:https://blog.csdn.net/jun4331247/article/details/51201825 通过设置系统属性(System Property)[persist.sy ...
- poj 1840 Eqs 【解五元方程+分治+枚举打表+二分查找所有key 】
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 13955 Accepted: 6851 Description ...
- wampserver2 配置ssl 经过验证 可用
本文原地址 http://blog.csdn.net/taosst/article/details/2182966 http://forum.wampserver.com/read.php?2,329 ...