当前位置:网站首页>sum of special numbers
sum of special numbers
2022-08-01 06:33: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;
}

边栏推荐
- Talk about the bugs in using for in to traverse the array in js
- 【视觉SLAM十四讲】第一章理论详解
- Leetcode第 304 场周赛
- vim configuration + ctag is as easy to read code as source insight
- 说说js中使用for in遍历数组存在的bug
- Why is the lightweight VsCode used more and more?Why eat my C drive 10G?How to Painlessly Clean VsCode Cache?Teach you how to lose weight for C drive
- matlab 风速模型 小波滤波
- Selenium: upload and download files
- 使用string 容器翻转 字母
- torch
猜你喜欢

Robot_Framework: keyword

Dbeaver connect the MySQL database and error Connection refusedconnect processing

数据湖:数据同步工具NiFi

Qt Widget project loading example of qml

first unique character in characters

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

WebSocket实现聊天功能

爬虫基本原理介绍、实现以及问题解决

Malicious attacks on mobile applications surge by 500%

太厉害了,终于有人能把文件上传漏洞讲的明明白白了
随机推荐
导致锁表的原因及解决方法
LeetCode每日一题(309. Best Time to Buy and Sell Stock with Cooldown)
Induction jian hai JustFE 2022/07/29 team, I learned the efficient development summary (years)
滚动条样式修改
Explosive 30,000 words, the hardest core丨Mysql knowledge system, complete collection of commands [recommended collection]
Vsce package after the Command failed: NPM list - production - parseable - the depth = 99999 - loglevel = error exception
Leetcode第 304 场周赛
Data organization -- singly linked list of the linear table
七、MFC序列化机制和序列化类对象
matplotlib pyplot
阿里云李飞飞:中国云数据库在很多主流技术创新上已经领先国外
微信小程序获取手机号phonenumber.getPhoneNumber接口开发
Seleniu: Common operations on elements
Dbeaver connect the MySQL database and error Connection refusedconnect processing
2022.7.26 Mock Competition
MVVM project development (commodity management system 1)
Bean的生命周期
ORACLE modify another user package (package)
爬虫基本原理介绍、实现以及问题解决
Selenium: element judgment