当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
Hunan institute of technology in 2022 ACM training sixth week antithesis
Matlab simulink particle swarm optimization fuzzy pid control motor pump
微信小程序用户登录auth.code2Session接口开发
WebSocket实现聊天功能
torch
点餐系统数据库设计--SQL Server
About making a progress bar for software initialization for Qt
湖仓一体电商项目(一):项目背景和架构介绍
LeetCode 0150. 逆波兰表达式求值
Robot_Framework: keyword
Selenium: Dropdown Box Actions
从底层结构开始学习FPGA(6)----分布式RAM(DRAM,Distributed RAM)
Vsce package after the Command failed: NPM list - production - parseable - the depth = 99999 - loglevel = error exception
vim configuration + ctag is as easy to read code as source insight
Dart 异常详解
Motion analysis and parameter optimization of crank-slider mechanism
2022.7.27 Selected lectures on good topics
Selenium: Introduction
How JS works
Flip letters using string container