Digital Roots—HDU1013 2016-05-06 10:25 85人阅读 评论(0) 收藏
Digital Roots
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.
24
39
0
6
3
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
char a[1000005];
int main()
{
int k, sum,sum1;
while (~scanf(" %s", a))
{
if (strcmp(a, "0") == 0)
break;
k = strlen(a);
sum = 0;
for (int i = 0; i < k; i++)
{
sum = sum + a[i] - '0';
} while (sum>9)
{
sum1 = 0;
while (sum != 0)
{
sum1 = sum1 + sum % 10;
sum /= 10;
}
sum = sum1;
}
printf("%d\n", sum); }
return 0; }
Digital Roots—HDU1013 2016-05-06 10:25 85人阅读 评论(0) 收藏的更多相关文章
- 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校赛-最大收益问题 分类: 比赛 2015-06-26 10:25 51人阅读 评论(0) 收藏
最大收益问题 Time Limit: 2000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 铁牌狗最近迷上了一款游戏,但铁牌狗实在是太笨了,他还是要请求你的帮助. 有 ...
- 博弈论入门小结 分类: ACM TYPE 2014-08-31 10:15 73人阅读 评论(0) 收藏
文章原地址:http://blog.csdn.net/zhangxiang0125/article/details/6174639 博弈论:是二人或多人在平等的对局中各自利用对方的策略变换自己的对抗策 ...
- DateTime日期格式获取 分类: C# 2014-04-15 10:36 233人阅读 评论(0) 收藏
c#.net 获取时间年月日时分秒格式 //获取日期+时间 DateTime.Now.ToString(); // 2008-9-4 20:02:10 DateTime.Now. ...
- Financial Management 分类: POJ 2015-06-11 10:51 12人阅读 评论(0) 收藏
Financial Management Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 164431 Accepted: ...
- C#中的线程(上)-入门 分类: C# 线程 2015-03-09 10:56 53人阅读 评论(0) 收藏
1. 概述与概念 C#支持通过多线程并行地执行代码,一个线程有它独立的执行路径,能够与其它的线程同时地运行.一个C#程序开始于一个单线程,这个单线程是被CLR和操作系统(也称为"主线 ...
- Hdu1728 逃离迷宫 2017-01-17 10:56 81人阅读 评论(0) 收藏
逃离迷宫 Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissi ...
- Codeforces758D Ability To Convert 2017-01-20 10:29 231人阅读 评论(0) 收藏
D. Ability To Convert time limit per test 1 second memory limit per test 256 megabytes input standar ...
- POI操作Excel常用方法总结 分类: B1_JAVA 2013-08-23 10:01 349人阅读 评论(0) 收藏
转载自:http://blog.csdn.net/xjun15/article/details/5805429 一. POI简介 Apache POI是Apache ...
随机推荐
- Business.Startup.Learning from Startup Mistakes at SpringSource
http://www.infoq.com/news/2014/07/startup-spring
- 如何选择稳定的PHP虚拟主机?
先评估自己的业务量有多大如果是新站且流量和数据量都不大的话,建议刚开始先购买低配的即可,待流量逐渐增大时在逐渐升级,灵活又省钱 带宽的限制 虚拟主机带宽是指同一时间内所能承载的数据的能力,直接关系大虚 ...
- How to program BMW KOMBI and NBTwith ENET E sys cable ICOM A2
This is how to set up Router or DHCP server for BMW KOMBI and NBT programming with Enet e sys cable ...
- linux下gcc默认搜索的头文件及库文件路径
转自:https://blog.csdn.net/fd315063004/article/details/7925854 一.头文件 gcc 在编译时如何去寻找所需要的头文件:※所以header fi ...
- Scrapy框架学习笔记
1.Scrapy简介 Scrapy是用纯Python实现一个为了爬取网站数据.提取结构性数据而编写的应用框架,用途非常广泛. 框架的力量,用户只需要定制开发几个模块就可以轻松的实现一个爬虫,用来抓取网 ...
- 杭电1518 Square(构成正方形) 搜索
HDOJ1518 Square Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- flask 中文编码解码
process.append("中文") print(process) # return Response(json.dumps(process), mimetype='appli ...
- SevenZipShaper压缩类
//7z下载或者自己去找个地址 nurget,github之类的 链接:https://pan.baidu.com/s/1__dPu7X5b8Xr_ej9ya7Kdg 密码:q8nwusing Sev ...
- python学习 day4 (3月5日)---列表
列表: 容器性数据 有序 可更改 大量数据 一.增 1.追加 append(objcet) 2.索引增加 Insert(index,元素) 3.迭代追加 extend(object) ...
- GDBT
理论知识: 第四范式自主研发算法GBDT(Gradient Boosting Decision Tree) GBDT是一种基分类器为决策树的集成学习方法.决策树是一种常见的机器学习算法,GBDT中使用 ...