1到N中1出现的个数
来源:互联网 发布:软件研发流程 编辑:程序博客网 时间:2024/05/21 10:27
#include <iostream>using namespace std;int count_one(int n){ if(n<1) return 0; int round = n; int base = 1; int count = 0; while(round>0) { int weight = round%10; round/=10; //count+=round; if(weight==1) count+=round*base+(n%10)+1; else if(weight>1) count+=round*base+base; else if(weight==0) count+=round*base; base*=10; } return count;}/* 若weight为0,则1出现次数为round*base 若weight为1,则1出现次数为round*base+former+1 若weight大于1,则1出现次数为rount*base+base*/int main(){ int n; while(cin>>n) { cout<<count_one(n)<<endl; } return 0;}
阅读全文
1 0
- 统计1到n中1的出现个数
- 1到N中1出现的个数
- 从1到n整数中1出现的个数
- 统计1到n这n个数中出现1的个数
- N个数中,1出现的次数
- 从1到N这N个数中1的出现了多少次?
- 从1到n这n个数中1的出现次数
- 给定一个正整数N计算从1到N中1出现的个数
- 1到n中1的个数
- 1到n中1的个数
- 1到n中1的个数
- 求0到n之间出现的"1"的个数
- 统计1到n之间的所有数字中1出现的个数
- 统计1到n之间的所有数字中1出现的个数
- 求1到N的数中1出现的个数
- 从1到n的数中1出现的个数&&寻找丑数
- 统计1到n之间的所有数字中1出现的个数
- 计算正整数1到N中出现的1的个数
- 论文阅读:Deep MANTA: A Coarse-to-fine Many-Task Network for joint 2D and 3D vehicle analysis
- 图像处理——sobel算子
- codefores544D
- 借书
- P2P原理之打洞
- 1到N中1出现的个数
- MySQL学习笔记--MySQL编程
- 函数模板与函数重载
- github用法笔记
- 解决用户的显性需求与隐性需求的SEO文章规范策略技巧
- Android入门之在子线程中更新UI
- 交直流配电网软件
- mybatis mapper映射配置时间类型对应oracle,java里的Date 类型 TIMESTAMP
- 二叉树的先序,中序,后序及其非递归遍历的方法