当前位置:网站首页>特别数的和
特别数的和
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;
}

边栏推荐
猜你喜欢
随机推荐
torch
Malicious attacks on mobile applications surge by 500%
小白的0基础教程SQL: 关系数据库概述 02
对于升级go1.18的goland问题
解决浏览器滚动条导致的页面闪烁问题
crypto-js使用
LeetCode 0150. Reverse Polish Expression Evaluation
After the image is updated, Glide loading is still the original image problem
LeetCode 0149. 直线上最多的点数
Selenium: upload and download files
Xiaobai's 0 Basic Tutorial SQL: An Overview of Relational Databases 02
uva12326
史上超强最常用SQL语句大全
七、MFC序列化机制和序列化类对象
Talk about the bugs in using for in to traverse the array in js
MVVM project development (commodity management system 1)
MVVM项目开发(商品管理系统一)
Selenium: Introduction
The solution to the inconsistency between the PaddleX deployment inference model and the GUI interface test results
小白的0基础教程SQL: 安装MYSQL 03









