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

边栏推荐
猜你喜欢

A,H,K,N

Srping bean in the life cycle
![Explosive 30,000 words, the hardest core丨Mysql knowledge system, complete collection of commands [recommended collection]](/img/7f/08b323ffc5b5f8e3354bee6775b994.png)
Explosive 30,000 words, the hardest core丨Mysql knowledge system, complete collection of commands [recommended collection]

LeetCode 0149. Maximum number of points on a line

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

Robot growth in China

The BP neural network based on MATLAB voice characteristic signal classification

第5章——以程序方式处理MySQL数据表的数据

数据湖:数据同步工具NiFi

阿里云李飞飞:中国云数据库在很多主流技术创新上已经领先国外
随机推荐
Robot growth in China
2022.7.27好题选讲
太厉害了,终于有人能把文件上传漏洞讲的明明白白了
Information system project managers must recite the work of the core test site (56) Configuration Control Board (CCB)
uva10825
[Translation] Securing cloud-native communications: From ingress to service mesh and beyond
曲柄滑块机构运动分析和参数优化
微信小程序获取手机号phonenumber.getPhoneNumber接口开发
Speed up your programs with bitwise operations
LeetCode 0150. Reverse Polish Expression Evaluation
从底层结构开始学习FPGA(6)----分布式RAM(DRAM,Distributed RAM)
Malicious attacks on mobile applications surge by 500%
权重等比分配
LeetCode 0149. 直线上最多的点数
Robot_Framework: commonly used built-in keywords
Selenium: form switching
Hunan institute of technology in 2022 ACM training sixth week antithesis
说说js中使用for in遍历数组存在的bug
Jupyter shortcuts
Dart 异常详解