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

边栏推荐
- crypto-js uses
- Robot growth in China
- Speed up your programs with bitwise operations
- 奇葩问题 npm install 报错 gyp ERR
- Detailed explanation of the crawler framework Scrapy
- 【视觉SLAM十四讲】第一章理论详解
- return; represents meaning
- 2022年牛客多校第四场补题
- matlab wind speed model wavelet filtering
- Sound Signal Processing Fundamental Frequency Detection and Time-Frequency Analysis
猜你喜欢

信息系统项目管理师必背核心考点(五十六)配置控制委员会(CCB)的工作

太厉害了,终于有人能把文件上传漏洞讲的明明白白了

Practical training Navicat Chinese and English mode switching

The solution to the inconsistency between the PaddleX deployment inference model and the GUI interface test results

Robot_Framework: Assertion

dbeaver连接MySQL数据库及错误Connection refusedconnect处理

Robot_Framework: keyword

matlab simulink 粒子群优化模糊pid控制的电机泵

leetcode125 验证回文串

Flip letters using string container
随机推荐
Selenium: Introduction
Check控件
MVVM项目开发(商品管理系统一)
Introduction to the basic principles, implementation and problem solving of crawler
轻量级的VsCode为何越用越大?为什么吃了我C盘10G?如何无痛清理VsCode缓存?手把手教你为C盘瘦身
leetcode125 Verify palindrome string
Selenium: element positioning
WebSocket implements chat function
Does flinkcdc have any solution for mysql's date field type conversion?
Dialogue with the father of MySQL: One excellent programmer is worth 5 ordinary programmers
Using FiddlerScript caught poly FiddlerScript 】 【 download
matplotlib pyplot
flinkcdc对mysql的date字段类型转化有什么解决思路么
Robot growth in China
Qt Widget 项目对qml的加载实例
第6章——数据库的安全性
[Translation] Securing cloud-native communications: From ingress to service mesh and beyond
曲柄滑块机构运动分析和参数优化
Windows taskbar icon abnormal solution
Information system project managers must recite the work of the core test site (56) Configuration Control Board (CCB)