博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1的个数
阅读量:4228 次
发布时间:2019-05-26

本文共 633 字,大约阅读时间需要 2 分钟。

#include <iostream>
using namespace std;
unsigned int tongji(int m);
unsigned int numOfone(unsigned int n);
void main()
{
unsigned int i(0);
cout << "Please input the number for calculate:";
cin >> i;
cout << tongji(i) << endl;
}
unsigned int tongji(int m)
{
if (m == 1)
{
return 1;
}
else
{
return tongji(m - 1) + numOfone(m);
}
}
unsigned int numOfone(unsigned int n)
{
unsigned int count = 0;
if (n / 10000 == 1)
{
count ++;
}
n %= 10000;
if (n / 1000 == 1)
{
count ++;
}
n %= 1000;
if (n / 100 == 1)
{
count ++;
}
n %= 100;
if (n / 10 == 1)
{
count ++;
}
n %= 10;
if (n / 1 == 1)
{
count ++;
}
return count;
}
// 5  =>  1 ;  13  =>  6

转载地址:http://mxdqi.baihongyu.com/

你可能感兴趣的文章
剑指Offer——丑数
查看>>
剑指Offer——字符串中第一个只出现一次的字符
查看>>
Linux 中的硬链接与软连接有什么区别
查看>>
Python 图像处理库
查看>>
使用PHPMailer-master发送邮件
查看>>
利用smtp协议实现命令行发送邮件
查看>>
利用php的mail()函数发送邮件
查看>>
(一).postman学习——前期知识准备
查看>>
qt入门级使用
查看>>
Web Stotage——本地储存详解及案例
查看>>
File Reader文件操作
查看>>
地理位置服务——navigator.geolocation
查看>>
地理位置服务——百度地图API
查看>>
js拖放事件详解及实战
查看>>
js字符串常用属性与方法
查看>>
C++递归算法案例
查看>>
C++算法——异或运算解决出现次数问题
查看>>
C++数据结构——顺序栈(基本代码实现与案例)
查看>>
C++数据结构——链队列(基本代码实现与案例)
查看>>
C++数据结构——顺序表的查找(简单顺序查找、有序表的二分查找、索引顺序的查找)
查看>>