【HDU - 1013 】Digital Roots (大数模拟)

题干:

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

解题报告:

      刚开始直接开longlong,wa了。

AC代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
char s[100000];
int b[100000];
int get(ll x) {int p = 0;while(x) {b[++p] = x%10;x/=10;}	return p;
}
int main()
{while(~scanf("%s",s)) {if(s[0] == '0') break;ll ans = 0;for(int i = 0; i<strlen(s); i++) ans += 1LL * (s[i] - '0');while(1) {int p = get(ans);if(p == 1) break;ans = 0;for(int i = 1; i<=p; i++)ans += 1LL * b[i];}printf("%d\n",b[1]);}return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441842.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

mete30是鸿蒙系统么,华为mete30pro什么时候能用上鸿蒙系统?

[其他]华为mete30pro什么时候能用上鸿蒙系统&#xff1f;8957电梯直达huafans01303113614新学乍练发表于 2021-4-21 21:43:19来自&#xff1a;HUAWEI Mate 30 Pro 5G最新回复 2021-4-22 12:10:10华为mete30pro什么时候能用上鸿蒙系统&#xff1f;能有确切的时间吗伊凡爱尔顿已臻…

【HDU - 1520】Anniversary party (树形dp)

题干&#xff1a; There is going to be a party to celebrate the 80-th Anniversary of the Ural State University. The University has a hierarchical structure of employees. It means that the supervisor relation forms a tree rooted at the rector V. E. Tretyako…

android assets 文件夹 复制,Android 中 Assets目录下 文件或文件夹的复制

1、文件或文件夹的复制/** 下面两个方法不是AsyncTask的接口** copyFileOrDir 目录复制* copyFile 文件复制*/private void copyFileOrDir(String path) {AssetManager assetManager mContext.getAssets();String assets[] null;try {assets assetManager.list(path);//复制…

python运算符中用来计算整商的是什么_零基础学python,看完这篇文章,你的python基础就差不多了...

Python基础语法1. 认识Python1.1 Python 简介Python 的创始人为吉多范罗苏姆&#xff08;Guido van Rossum&#xff09;。Python 的设计目标&#xff1a;一门简单直观的语言并与主要竞争者一样强大开源&#xff0c;以便任何人都可以为它做贡献代码像纯英语那样容易理解适用于短…

*【HDU - 1242 】 Rescue (反向dfs,或bfs)

题干&#xff1a; Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M < 200) matrix. There are WALLs, ROADs, and GUARDs in the prison. Angels friends want to save Angel. Their task is: approach Ang…

华为鸿蒙os系统转正,华为鸿蒙OS系统正式官宣,转正工作提上日程,明年多款终端将使用...

华为鸿蒙OS系统相信很多小伙伴都不陌生&#xff0c;作为国内现如今顶尖的科技企业。华为这些年的发展也是十分迅速的&#xff0c;而再快速的发展过程中。更多的用户对于华为的新款系统也充满了好奇&#xff0c;要知道一款属于国人自己的国产系统。在之前的国内手机上是几乎不存…

【FZU - 2140 】Forever 0.5 (计算几何,构造)

题干&#xff1a; Given an integer N, your task is to judge whether there exist N points in the plane such that satisfy the following conditions: 1. The distance between any two points is no greater than 1.0. 2. The distance between any point and the ori…

map型字段 mongodb_MongoDB极简教程

来源&#xff1a;我没有三颗心脏1.MongDB 简介MongoDB(来自于英文单词“Humongous”&#xff0c;中文含义为“庞大”)是可以应用于各种规模的企业、各个行业以及各类应用程序的开源数据库。作为一个适用于敏捷开发的数据库&#xff0c;MongoDB 的数据模式可以随着应用程序的发展…

html 如何改变图片形状,图形变换的三种方式是什么?

图形变换的三种方式1、平移平移&#xff0c;是指在同一平面内&#xff0c;将一个图形上的所有点都按照某个直线方向做相同距离的移动&#xff0c;这样的图形运动叫做图形的平移运动&#xff0c;简称平移。平移不改变图形的形状和大小。图形经过平移&#xff0c;对应线段相等&am…

springboot html压缩,springboot 请求响应压缩

官方文档原文&#xff1a;[https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/reference/htmlsingle/\#how-to-enable-http-response-compression][https_docs.spring.io_spring-boot_docs_2.1.5.RELEASE_reference_htmlsingle_how-to-enable-http-response-compression]…

Trie树(字典树)详细知识点及其应用

Trie&#xff0c;又经常叫前缀树&#xff0c;字典树等等。它有很多变种&#xff0c;如后缀树&#xff0c;Radix Tree/Trie&#xff0c;PATRICIA tree&#xff0c;以及bitwise版本的crit-bit tree。当然很多名字的意义其实有交叉。 定义 在计算机科学中&#xff0c;trie&#x…

aip格式转化为pdf_python提取pdf文档中的表格数据、svg格式转换为pdf

提取pdf文件中的表格数据原文链接https://www.analyticsvidhya.com/blog/2020/08/how-to-extract-tabular-data-from-pdf-document-using-camelot-in-python/另外还参考了这篇文章https://camelot-py.readthedocs.io/en/master/实现提取pdf文档中的表格数据需要使用camelot模块…

html验证邮箱自动,html5+JavaScript进行邮箱地址验证

html5 网页特效 邮箱地址验证body, input, textarea {font-family: "helvetica", arial, helvetica;}label {display: block;float: left;clear: left;text-align: right;width: 100px;margin-right: 10px;}p { padding: 10px; }fieldset { border: 1px solid #ccc; …

6 rethad 自定义硬盘_图文详解zabbix配置自定义监控项过程

概述今天主要介绍一下zabbix如何去配置自定义监控模板&#xff0c;下面一起来看看吧&#xff01;一、模板1、概念模板(template)&#xff1a;可以应用到主机上的实体(包括监控项、触发器、数据图、图表、监控分类、低级的自动发现规则)的集合。当一个模板被应用到一个主机后&am…

【HDU - 1085 】Holding Bin-Laden Captive! (母函数)

题干&#xff1a; We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But recently, it is reported that he hides in Hang Zhou of China! “Oh, God! How terrible! ” Don’t be so afraid, guys. Although he hides in a…

html text align属性,HTML canvas

实例在位置 150 创建一条红线。位置 150 是下面实例中定义的所有文本的锚点。请研究每种 textAlign 属性值的效果&#xff1a;YourbrowserdoesnotsupporttheHTML5canvastag.JavaScript&#xff1a;var cdocument.getElementById("myCanvas");var ctxc.getContext(&qu…

html超链接点不了_HTML、CSS、JS都有哪些区别?不看必悔

划重点HTML、CSS、及JS的区别有哪些&#xff1f;在日常学习中&#xff0c;html&#xff0c;css和js我们都学过&#xff0c;起初分不清这三者的区别和联系&#xff0c;随着知识的增长&#xff0c;有了一些体会。看一下这三项技术都是什么&#xff0c;能干什么&#xff1f;web前端…

【Codeforces - 378C】Maze(dfs,思维)

题干&#xff1a; Pavel loves grid mazes. A grid maze is an n  m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty…

2019游戏 f1_2019年F1中国大奖赛激情开跑,这款手游带你体验真实F1的魅力

不知不觉&#xff0c;F1中国大奖赛进入第16个年头。你是否还记得2018年的F1中国大奖赛&#xff0c;真是跌宕起伏&#xff0c;红牛队车手里卡多在第三次练习赛中爆缸&#xff0c;之后在车队技师的努力下才赶上排位赛&#xff0c;结果他在正赛时第6位发车&#xff0c;竟然超出对手…

html自定义字体demo,如何在HTML网站上安装自定义字体

是的&#xff0c;您可以使用名为 font-face的CSS功能。它只在CSS3中正式批准&#xff0c;但已经在CSS2中提出并实现&#xff0c;并且在IE中已经支持相当长的时间。你在CSS中声明它像这样&#xff1a;font-face { font-family: Delicious; src: url(Delicious-Roman.otf); }font…