当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
仿牛客网项目总结
matlab 风速模型 小波滤波
Induction jian hai JustFE 2022/07/29 team, I learned the efficient development summary (years)
About making a progress bar for software initialization for Qt
leetcode43 字符串相乘
Introduction to the basic principles, implementation and problem solving of crawler
Robot growth in China
Hunan institute of technology in 2022 ACM training sixth week antithesis
A,H,K,N
可视化全链路日志追踪
随机推荐
仿牛客网项目总结
Leetcode第 304 场周赛
Selenium: upload and download files
对于升级go1.18的goland问题
Dbeaver connect the MySQL database and error Connection refusedconnect processing
Compare two objects are the same depth
Srping中bean的生命周期
阿里三面:MQ 消息丢失、重复、积压问题,该如何解决?
第5章——以程序方式处理MySQL数据表的数据
return; represents meaning
混合型界面:对话式UI的未来
The Bean's life cycle
Talk about the bugs in using for in to traverse the array in js
Does flinkcdc have any solution for mysql's date field type conversion?
实战演练 Navicat 中英文模式切换
JS的运行原理
Motion analysis and parameter optimization of crank-slider mechanism
Dart exception details
特别数的和
WebSocket实现聊天功能