统计0-n数字中出现k的次数

/*** 统计0-n数字中出现k的次数,其中k范围为0-9
*/
public static int countOne(int k, int n) {if (k > n) {return 0;}int sum = 0;int right = 0;for (int i = 0; n > 0; i++) {int last = n % 10;sum += last * i * (int) Math.pow(10, i - 1);if (k == 0) {sum -= (int) Math.pow(10, i);}if (last > k) {sum += (int) Math.pow(10, i);}if (last == k) {sum += right + 1;}right += last * Math.pow(10, i);n /= 10;}return sum + (0 == k ? 1 : 0);}

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

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

相关文章

房价预测 search Search 中对数据预处理的学习

对于缺失的数据: 我们对连续数值的特征做标准化(standardization):设该特征在整个数据集上的均值为 μ ,标准差为 σ 。那么,我们可以将该特征的每个值先减去 μ 再除以 σ 得到标准化后的每个特征值。对于…

3.6.1.非阻塞IO

本节讲解什么是非阻塞IO,如何将文件描述符修改为非阻塞式 3.6.1.1、阻塞与非阻塞 (1)阻塞是指函数调用会被阻塞。本质是当前进程调用了函数,进入内核里面去后,因为当前进程的执行条件不满足,内核无法里面完…

rstudio 管道符号_R中的管道指南

rstudio 管道符号R基础知识 (R Fundamentals) Data analysis often involves many steps. A typical journey from raw data to results might involve filtering cases, transforming values, summarising data, and then running a statistical test. But how can we link al…

蒙特卡洛模拟预测股票_使用蒙特卡洛模拟来预测极端天气事件

蒙特卡洛模拟预测股票In a previous article, I outlined the limitations of conventional time series models such as ARIMA when it comes to forecasting extreme temperature values, which in and of themselves are outliers in the time series.在上一篇文章中 &#…

iOS之UITraitCollection

UITraitCollection 为表征 size class 而生,用来区分设备。你可以在它身上获取到足以区分所有设备的特征。 UITraitEnvironment 协议、UIContentContainer 协议 UIViewController 遵循了这两个协议,用来监听和设置 traitCollection 的变化。 protocol UI…

直方图绘制与直方图均衡化实现

一,直方图的绘制 1.直方图的概念: 在图像处理中,经常用到直方图,如颜色直方图、灰度直方图等。 图像的灰度直方图就描述了图像中灰度分布情况,能够很直观的展示出图像中各个灰度级所 占的多少。 图像的灰度直方图是灰…

eclipse警告与报错的修复

1.关闭所有eclipse校验 windows->perference->validation disable all 2.Access restriction: The constructor BASE64Decoder() is not API (restriction on required library C:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar) 在builde path 移除jre,再…

时间序列因果关系_分析具有因果关系的时间序列干预:货币波动

时间序列因果关系When examining a time series, it is quite common to have an intervention influence that series at a particular point.在检查时间序列时,在特定时间点对该序列产生干预影响是很常见的。 Some examples of this could be:例如: …

微生物 研究_微生物监测如何工作,为何如此重要

微生物 研究Background背景 While a New York Subway station is bustling with swarms of businessmen, students, artists, and millions of other city-goers every day, its floors, railings, stairways, toilets, walls, kiosks, and benches are teeming with non-huma…

Linux shell 脚本SDK 打包实践, 收集assets和apk, 上传FTP

2019独角兽企业重金招聘Python工程师标准>>> git config user.name "jenkins" git config user.email "jenkinsgerrit.XXX.net" cp $JENKINS_HOME/maven.properties $WORKSPACE cp $JENKINS_HOME/maven.properties $WORKSPACE/app cp $JENKINS_…

opencv:卷积涉及的基础概念,Sobel边缘检测代码实现及卷积填充模式

具体参考我的另一篇文章: opencv:卷积涉及的基础概念,Sobel边缘检测代码实现及Same(相同)填充与Vaild(有效)填充 这里是对这一篇文章的补充! 卷积—三种填充模式 橙色部分为image, 蓝色部分为…

怎么查这个文件在linux下的哪个目录

因为要装pl/sql所以要查找tnsnames.ora文件。。看看怎么查这个文件在linux下的哪个目录 find / -name tnsnames.ora 查到: /opt/app/oracle/product/10.2/network/admin/tnsnames.ora/opt/app/oracle/product/10.2/network/admin/samples/tnsnames.ora 还可以用loca…

无法从套接字中获取更多数据_数据科学中应引起更多关注的一个组成部分

无法从套接字中获取更多数据介绍 (Introduction) Data science, machine learning, artificial intelligence, those terms are all over the news. They get everyone excited with the promises of automation, new savings or higher earnings, new features, markets or te…

web数据交互_通过体育运动使用定制的交互式Web应用程序数据科学探索任何数据...

web数据交互Most good data projects start with the analyst doing something to get a feel for the data that they are dealing with.大多数好的数据项目都是从分析师开始做一些事情,以便对他们正在处理的数据有所了解。 They might hack together a Jupyter n…

C# .net 对图片操作

using System.Drawing;using System.Drawing.Drawing2D;using System.Drawing.Imaging;public class ImageHelper{/// <summary>/// 获取图片中的各帧/// </summary>/// <param name"pPath">图片路径</param>/// <param name"pSaveP…

数据类型之Integer与int

数据类型之Integer与int Java入门 基本数据类型 众所周知&#xff0c;Java是面向对象的语言&#xff0c;一切皆对象。但是为了兼容人类根深蒂固的数据处理习惯&#xff0c;加快常规数据的处理速度&#xff0c;提供了9种基本数据类型&#xff0c;他们都不具备对象的特性&#xf…

PCA(主成分分析)思想及实现

PCA的概念&#xff1a; PCA是用来实现特征提取的。 特征提取的主要目的是为了排除信息量小的特征&#xff0c;减少计算量等。 简单来说&#xff1a; 当数据含有多个特征的时候&#xff0c;选取主要的特征&#xff0c;排除次要特征或者不重要的特征。 比如说&#xff1a;我们要…

【安富莱二代示波器教程】第8章 示波器设计—测量功能

第8章 示波器设计—测量功能 二代示波器测量功能实现比较简单&#xff0c;使用2D函数绘制即可。不过也专门开辟一个章节&#xff0c;为大家做一个简单的说明&#xff0c;方便理解。 8.1 水平测量功能 8.2 垂直测量功能 8.3 总结 8.1 水平测量功能 水平测量方…

深度学习数据更换背景_开始学习数据科学的最佳方法是了解其背景

深度学习数据更换背景数据科学教育 (DATA SCIENCE EDUCATION) 目录 (Table of Contents) The Importance of Context Knowledge 情境知识的重要性 (Optional) Research Supporting Context-Based Learning (可选)研究支持基于上下文的学习 The Context of Data Science 数据科学…