ZOJ_1115_Digital Roots

【技能---ubuntu20.04更换国内镜像源】 安装好ubuntu20.04后,在下载软件等安装包的时候,速度特别的慢,为此就想着更换一下镜像源,以此来增加下载的速度!!!下面是换源的具体流程!!!提示:以下是本篇文章正文内容,下面案例可供参考以上到这里就更换完软件源了,如有不足之处,请大家斧正!!! 阅读详情
Digital Roots

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Background

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.


Example

Input


24
39
0
Output
6
3



     

题意和思路:题目就是定义了一个概念树根,它必须是一位的,得到方式是各个数位的和,因为要求是一位所以如果不是一位,则重复这样的流程,即继续将各个位数相加,直到得到树根为止。这题理解题意,做起来很简单。

注意点:一般来说第一遍很大可能是错误的,就是超时了,因为这里可能是很大的整数,所以第一次处理的时候将其看成字符串,然后字符串的各个位数相加,之后再按整数的方式处理就不会超时的,我一开始也错了。。。简单题也不要掉以轻心。

Sample Program Here
#include<iostream>
#include<string>
using namespace std;


//////用来得到各个位数的和
int process(int a){
	int sum=0;
	while(a!=0){
	  sum+=a%10;
	  a/=10;
	}

	return sum;
}

int main(){
 int root=0;  //a是输入的数,root 是相应的数根
 string a;
 while(cin>>a){
    root=0;
    if(a.length()==1&&a[0]=='0') break;

	//得到第一次计算的各位数和
	for(int i=0;i<a.length();i++){
		root+=a[i]-'0';
	}


    //如果处理后不是一位的则继续操作
	while(root/10!=0){   
	   root=process(root);
	}

	cout<<root<<endl;

 }
 return 0;
}




RK3588高速接口实战-PCIE 摘要: RK3588的PCIe接口支持PCIe 3.0x4和PCIe 2.1x1/x2,具备Root Complex和Endpoint模式,适用于NVMe SSD、5G模块等高速设备。硬件设计需注意85Ω/100Ω阻抗匹配、220nF AC耦合电容及100MHz参考时钟。设备树需配置控制器节点、PHY模式和IOMMU映射(RC模式用iommu-map,EP模式用iommus)。调试时可通过lspci检查链路状态,dmesg查看训练日志,perf分析性能。常见问题包括设备识别失败(检查复位时序、PHY配置)、 阅读详情

相关推荐

火星遥感数据的获取与处理工具安装详解

有关火星遥感影像数据的那些事...

FengYingLuo的博客 5570

ZOJ 1115 Digital Roots 水题

刚开始的时候,代码里有注释,结果CE。 后来,WA,奇了怪了。挺简单的一道题哇。 事实上是我没考虑大整数,不能用int,得用字符串。 WA的代码:方法二:http://blog.sina.com.cn/s/blog_6ce23f8f0100loc4.html # include int main() { int a,i,sum,t; while(scanf("%d",&a

【Zhou Ping 's 解题报告】为了有资格参加亚洲区ACM而奋斗 1224

信息安全-入侵检测技术原理与应用

入侵检测技术原理与应用、入侵检测概述、入侵检测技术、入侵检测系统组成与分类、入侵检测系统主要产品与技术指标、入侵检测系统应用

我的个人博客 1万+

zoj 1115 Digital Roots

//刚开始做这题的时候,以为是一题好简单好简单的题,但是我却无考虑到当输入的数为非常大的时候这种情况! //思考还是不够周密!要加强锻炼才可以! #include "iostream" #include "string" using namespace std; int root (int n) { if (n < 10) return n; else { int temp = n

yzl_rex 840

手把手教你:在openEuler 22.03上离线搞定OpenSSH 9.8升级(CentOS 7.9通用)

本文详细介绍了在openEuler 22.03和CentOS 7.9系统上离线升级OpenSSH 9.8的完整流程,包括准备工作、离线包获取、安装步骤、服务管理及回滚方案。特别针对无外网环境的企业服务器,提供安全可靠的离线升级解决方案,帮助运维人员有效提升系统安全性。

weixin_30682415的博客 192

GPIB通讯的代码怎么写

GPIB(General Purpose Interface Bus)是一种用于连接计算机和测试设备的接口标准。 在写 GPIB 通讯的代码时,首先需要在计算机上安装 GPIB 驱动程序。然后,使用相应的编程语言和 GPIB 库函数来操作 GPIB 设备。 下面是一个使用 Python 语言和 pyvisa 库来实现 GPIB 通讯的示例代码: import visa# 创建 Visa 资源管理器...

weixin_35752645的博客 1545

ZOJ1115 Digital Roots

减少第一轮求和的计算量是关键 #include<iostream> #include<string> #include<unordered_map> using namespace std; int main(){ string str; while(cin>>str){ if(str == "0") break; int ans = 0...

姚军 226

SAP软件外币评估系统配置与操作

文章摘要:本文详细介绍了SAP系统中外币评估的流程、策略及系统操作。外币评估是期末关账的重要环节,主要针对外币未清项目及资产/负债进行汇率重估,生成评估差异过账以反映真实财务状况。文中阐述了三种评估策略(不评估、增量评估、期末评估冲回)及适用场景,并提供了SAP系统外币评估的具体操作步骤(FAGL_FCV/FAGL_FC_VAL事务码)。同时,讲解了货币资金科目和未清项管理科目的评估差异处理方式,以及相关的系统配置(OB59、OBA1等)。文章还区分了已实现和未实现汇兑损益的会计处理,为企业外币业务管理提供

weixin_40672823的博客 1958

Digital Roots——ZOJ 1115

Background 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

小小梅花 503

Halcon实战:5分钟搞定灰度图转热力图(附完整代码)

本文提供了一份Halcon实战指南,详细讲解如何在5分钟内将灰度图转换为直观的热力图。通过核心代码演示了利用HSV颜色模型进行色彩映射的原理与步骤,包括图像归一化、通道构建与空间转换,并附赠了深度图可视化等进阶应用技巧,帮助工程师快速提升图像分析效果。

weixin_29240343的博客 282

【VAX 小番茄安装详细步骤】

本文详细介绍了在VS2022环境下安装Visual Assist X(番茄助手)的步骤及常见问题解决方案。主要内容包括:安装前的兼容性设置(需修改为Windows7兼容模式)、安装流程(卸载旧版本、勾选对应VS版本、替换关键dll文件)以及常见问题处理(如安装失败、工具栏图标缺失等)。文章提供了完整的下载链接和操作截图,特别强调了安装失败后的清理方法(注册表、安装目录和残余文件删除)。最后给出了安装成功后的测试运行指引。

qq_23962581的博客 1714

ZOJ 1115: Digital Roots

题目的意思是 给定一个整数 算digital root 比如 13579  1+3+5+7+9= 25 2+5=7 所以就返回7 positive integers注意题目里说的"positive integer" 不一定是int型 所以第一轮要用字符串处理 不过这题通过率倒是很低 22.80% (9047/39670) 难度系数=0 import j

业余程序员_专业吃货 774

Reeds-Shepp曲线公式推导及代码实现-第二部分(共三部分)

文章目录2. Reeds-Shepp求解2.1 L+S+L+L^+S^+L^+L+S+L+2.2 L+S+R+L^+S^+R^+L+S+R+2.3 L+R−L+L^+R^-L^+L+R−L+2.4 L+R−L−L^+R^-L^-L+R−L−2.5 L+R+L−L^+R^+L^-L+R+L−2.6 L+Rβ+Lβ−R−L^+R_{\beta}^+L_{\beta}^-R^-L+Rβ+​Lβ−​R−2.7 L+Rβ−Lβ−R+L^+R_{\beta}^-L_{\beta}^-R^+L+Rβ−​Lβ−​R+2.8

jianmo的博客 1211

ZOJ 1115 Digital Roots —— C++

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 ...

点滴博客 344

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

zoj1115 Digital Roots

Digital Roots Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 1115 Appoint description:  System Crawler  (2016-04-26) Description

neuike的博客 333

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

ZOJ 1115 Digital Roots

题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1115  Hint: 本题的关键是减小第一轮求和的计算量。要把一个整数的各位分离出来,如果采用取余的方法分离各位,  如果数据量太大,肯定会超时。这里把整数当成字符串读入,然后读取每个字符,采用map进行键值映射,  就相当于将各位分离了,这种方法是比较省时

gemire的专栏 695

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

zoj1115-Digital Roots

不知道str.front()在哪个库= =G++没有,只好改成str[0] #include #include using namespace std; int main() { int sum,i; string str(1000,'1'); cout<<str.front()<<endl; return 0; }

0≡(-∞,+∞) 508

ZOJ 1115-Digital Roots

原题地址: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1115 #include //#include #include #include using namespace std; int main() { //ifstream cin("in.txt"); string s;

编程碎片流 436

数根计算ZOJ 1115 Digital Roots

字根求解两种方法。

雪松-不仅仅是程序员 1256

ZOJ Problem 1115 Digital Roots

/* 必须用字符串来处理,测试数据会很大*/#include #include int main(){ char s[1000],*p; int n; while(scanf("%s",s)!=EOF){  if(strcmp(s,"0")==0)   break;    while(strlen(s)>1){   for(n=0,p=s;*p;p++)    n+=*p-0;   s

技术是生活 1076

ZOJ 1115 Digital Roots (C)

题目 Background 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...

w_m_w_m_w_m_w_m的博客 206
上一篇: ZOJ_1067_Color Me Less
下一篇: 字符串分割(C++)
wankaiming
博客等级 码龄15年 49粉丝 27原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值