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

边栏推荐
- AspNet.WebApi.Owin 自定义Token请求参数
- 表的创建、修改与删除
- 太厉害了,终于有人能把文件上传漏洞讲的明明白白了
- After the image is updated, Glide loading is still the original image problem
- The BP neural network based on MATLAB voice characteristic signal classification
- 「游戏引擎 浅入浅出」4.1 Unity Shader和OpenGL Shader
- first unique character in characters
- ORACLE modify another user package (package)
- 微信小程序获取手机号phonenumber.getPhoneNumber接口开发
- Win任务栏图标异常解决
猜你喜欢
随机推荐
微信小程序用户登录auth.code2Session接口开发
Information system project managers must recite the work of the core test site (56) Configuration Control Board (CCB)
Hunan institute of technology in 2022 ACM training sixth week antithesis
第5章——以程序方式处理MySQL数据表的数据
2022.7.27好题选讲
matplotlib pyplot
LeetCode 0150. 逆波兰表达式求值
matlab simulink 粒子群优化模糊pid控制的电机泵
curl (7) Failed connect to localhost8080; Connection refused
matplotlib pyplot
阿里云李飞飞:中国云数据库在很多主流技术创新上已经领先国外
leetcode43 字符串相乘
Dell PowerEdge Server R450 RAID Configuration Steps
史上超强最常用SQL语句大全
Win任务栏图标异常解决
"By sharing" northwestern university life service | | bytes a second interview on three sides by HR
torch
weight distribution
声音信号处理基频检测和时频分析
Xiaobai's 0 Basic Tutorial SQL: An Overview of Relational Databases 02









