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 ...
随机推荐
- 让intellij挂在异常处,特别是出现null pointer的地方
1 在Intellij中设置java exception breakpoint 在调试模式下,run->view breakpoints 在java exception breakpoints- ...
- Python菜鸟之路:Python基础-操作缓存memcache、redis
一.搭建memcached和redis 略,自己去百度吧 二.操作Mmecached 1. 安装API python -m pip install python-memcached 2. 启动memc ...
- Onenet GPS上传经纬度的格式 笔记
首先搞清楚几个问题: 1.GPS输出的经纬度 GPS获取的数据: 3438.1633,N,11224.4992,E 格式是ddmm.mmmmm 2.Onenet服务器识别的经纬度坐标格式 服务器识别需 ...
- php基本语法与函数
1.标记与注释 <?php 代码 ?> 用/* */注释一段代码, 用 // 注释一行代码 /** */文档注释 注意:若php下面只有php代码没有别的代码,那么最好不要加 ...
- vim 操作符命令和位移(如删除和修改)
一.字符删除命令:x,d,D x 删除光标下的字符,前面可以加入命令计数,如:5x 代表删除从当前光标到后面的5个字符,包括空格: X 删除光标前面的一个字符: dw 删除光标下到word后的数据: ...
- hiho一下 第二十九周 最小生成树三·堆优化的Prim算法【14年寒假弄了好长时间没搞懂的prim优化:prim算法+堆优化 】
题目1 : 最小生成树三·堆优化的Prim算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 回到两个星期之前,在成功的使用Kruscal算法解决了问题之后,小Ho产生 ...
- Spring Cloud之网关
接口的分类: 开放接口:可以授权一些接口口OAuth2.0协议方式 第三方联合登录 内部接口: 一般只能在局域网中进行访问,服务与服务之间关系都在同一个微服务系统中.目的是为了保证安全问题 接口设 ...
- App开发流程之创建项目和工程基本配置
我的开发环境为:Mac OS X EI Capitan(10.11.6),Xcode 7.3.1 首先说明一下这个项目的初衷,我并非要创建一个完整的上架应用,旨在创建一个可运行的,通用配置.架构,提供 ...
- tkinter比较常用的组件
1.输入框组件 输入框(Entry)用来输入单行内容,可以方便地向程序传递用户参数.这里通过一个转换摄氏度和华氏度的小程序来演示该组件的使用. import tkinter as tk def btn ...
- Druid:一个用于大数据实时处理的开源分布式系统——大数据实时查询和分析的高容错、高性能开源分布式系统
转自:http://www.36dsj.com/archives/28590 Druid 是一个用于大数据实时查询和分析的高容错.高性能开源分布式系统,旨在快速处理大规模的数据,并能够实现快速查询和分 ...