当前位置:网站首页>特别数的和
特别数的和
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;
}
边栏推荐
猜你喜欢
随机推荐
【翻译】确保云原生通信的安全:从入口到服务网及更远的地方
uva12326
Dbeaver connect the MySQL database and error Connection refusedconnect processing
NUMPY
matlab simulink 粒子群优化模糊pid控制的电机泵
Seleniu: Common operations on elements
return; represents meaning
Dell PowerEdge Server R450 RAID Configuration Steps
Selenium: element positioning
Dart 异常详解
LeetCode 0150. 逆波兰表达式求值
Selenium: Introduction
Compare two objects are the same depth
The BP neural network based on MATLAB voice characteristic signal classification
leetcode43 string multiplication
Flip letters using string container
WebSocket实现聊天功能
[Translation] Securing cloud-native communications: From ingress to service mesh and beyond
MySQL row locks and gap locks
Speed up your programs with bitwise operations