当前位置:网站首页>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;
}

边栏推荐
猜你喜欢

爬虫框架 Scrapy 详解

WebSocket implements chat function

Matlab simulink particle swarm optimization fuzzy pid control motor pump

curl (7) Failed connect to localhost8080; Connection refused

About making a progress bar for software initialization for Qt

MySQL row locks and gap locks

NIO编程

从购买服务器到网站搭建成功保姆级教程~超详细

Robot_Framework: commonly used built-in keywords

Hunan institute of technology in 2022 ACM training sixth week antithesis
随机推荐
点餐系统数据库设计--SQL Server
leetcode43 字符串相乘
dbeaver连接MySQL数据库及错误Connection refusedconnect处理
uva12326
mysql中添加字段的相关问题
mysql的行锁和间隙锁
爆肝3万字,最硬核丨Mysql 知识体系、命令全集 【建议收藏 】
The Bean's life cycle
将CSV文件快速导入MySQL中
爬虫框架 Scrapy 详解
ORACLE modify another user package (package)
[Translation] Securing cloud-native communications: From ingress to service mesh and beyond
小白的0基础教程SQL: 什么是SQL 01
「游戏引擎 浅入浅出」4.1 Unity Shader和OpenGL Shader
从离线到实时对客,湖仓一体释放全量数据价值
字符中的第一个唯一字符
Dialogue with the father of MySQL: One excellent programmer is worth 5 ordinary programmers
Bean的生命周期
Matlab simulink particle swarm optimization fuzzy pid control motor pump
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