当前位置:网站首页>特别数的和
特别数的和
2022-08-01 06:23:00 【Ding Jiaxiong】
题目
小明对数位中含有 2、0、1、9 的数字很感兴趣(不包括前导 0),在 1 到 40 中这样的数包括 1、2、9、10 至 32、39 和 40,共 28 个,他们的和是 574。
请问,在 1 到 n 中,所有这样的数的和是多少?
输入格式
共一行,包含一个整数 n。
输出格式
共一行,包含一个整数,表示满足条件的数的和。
数据范围
1≤n≤10000
输入样例:
40
输出样例:
574
思路分析


题解
#include<iostream>
using namespace std;
int main(){
int n;
cin >> n;
int res = 0;
for(int i = 1; i <= n; i++){
int x = i;
while(x){
int t = x % 10; //取出
x /= 10; //删掉
//判断
if(t == 2 || t == 0 || t == 1 || t == 9){
res += i;
break;
}
}
}
cout << res << endl;
return 0;
}

边栏推荐
- 上课作业(7)——#598. 取余运算(mod)
- 2022.7.27好题选讲
- Compare two objects are the same depth
- The Bean's life cycle
- matlab simulink 粒子群优化模糊pid控制的电机泵
- leetcode125 Verify palindrome string
- LeetCode 0150. 逆波兰表达式求值
- Bean的生命周期
- Vsce package after the Command failed: NPM list - production - parseable - the depth = 99999 - loglevel = error exception
- datagrip 报错 “The specified database userpassword combination is rejected...”的解决方法
猜你喜欢

实战演练 Navicat 中英文模式切换

基于MATLAB的BP神经网络进行语音特征信号分类

About making a progress bar for software initialization for Qt

AspNet.WebApi.Owin 自定义Token请求参数

第5章——以程序方式处理MySQL数据表的数据

mysql中添加字段的相关问题

【视觉SLAM十四讲】第一章理论详解

WebSocket implements chat function

Using FiddlerScript caught poly FiddlerScript 】 【 download

测试工具(四)Jenkins环境搭建与使用
随机推荐
A,H,K,N
CSP-S2019兴奋不已
Check控件
Jupyter shortcuts
2022.7.27 Selected lectures on good topics
点餐系统数据库设计--SQL Server
Selenium: Manipulating Cookies
MVVM project development (commodity management system 1)
The Bean's life cycle
WebSocket implements chat function
滚动条样式修改
太厉害了,终于有人能把文件上传漏洞讲的明明白白了
weight distribution
微信小程序获取手机号phonenumber.getPhoneNumber接口开发
dbeaver连接MySQL数据库及错误Connection refusedconnect处理
After the image is updated, Glide loading is still the original image problem
flinkcdc对mysql的date字段类型转化有什么解决思路么
Robot growth in China
深度比较两个对象是否相同
从底层结构开始学习FPGA(6)----分布式RAM(DRAM,Distributed RAM)