当前位置:网站首页>特别数的和
特别数的和
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;
}
边栏推荐
- Induction jian hai JustFE 2022/07/29 team, I learned the efficient development summary (years)
- 可视化全链路日志追踪
- Dialogue with the father of MySQL: One excellent programmer is worth 5 ordinary programmers
- A,H,K,N
- MVVM项目开发(商品管理系统一)
- Information system project managers must recite the work of the core test site (56) Configuration Control Board (CCB)
- 安装SQL Server详细教程
- About making a progress bar for software initialization for Qt
- Selenium: JS operation
- Selenium: Introduction
猜你喜欢
点餐系统数据库设计--SQL Server
【MySQL必知必会】 表的优化 | 充分利用系统资源
Flip letters using string container
第5章——以程序方式处理MySQL数据表的数据
JS的运行原理
Hunan institute of technology in 2022 ACM training sixth week antithesis
dbeaver连接MySQL数据库及错误Connection refusedconnect处理
安装SQL Server详细教程
first unique character in characters
leetcode43 string multiplication
随机推荐
LeetCode 0150. Reverse Polish Expression Evaluation
Selenium: element positioning
爆肝3万字,最硬核丨Mysql 知识体系、命令全集 【建议收藏 】
【FiddlerScript】利用FiddlerScript抓包保利威下载
2022.7.27 Selected lectures on good topics
CSP-S2019 Day1
uva10825
点餐系统数据库设计--SQL Server
2022年牛客多校第四场补题
第5章——以程序方式处理MySQL数据表的数据
头歌MySQL数据库实训答案 有目录
Selenium: browser operation
仿牛客网讨论社区项目—项目总结及项目常见面试题
Qt Widget project loading example of qml
曲柄滑块机构运动分析和参数优化
从零开始—仿牛客网讨论社区项目(一)
响应式织梦模板园林花卉类网站
MVVM project development (commodity management system 1)
WebSocket implements chat function
datagrip 报错 “The specified database userpassword combination is rejected...”的解决方法