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

边栏推荐
- 【FiddlerScript】利用FiddlerScript抓包保利威下载
- 仿牛客网讨论社区项目—项目总结及项目常见面试题
- 测试工具(四)Jenkins环境搭建与使用
- 【翻译】确保云原生通信的安全:从入口到服务网及更远的地方
- Does flinkcdc have any solution for mysql's date field type conversion?
- What should I do if the neural network cannot be trained?
- 仿牛客网项目总结
- datagrip 报错 “The specified database userpassword combination is rejected...”的解决方法
- Dart exception details
- weight distribution
猜你喜欢

Sound Signal Processing Fundamental Frequency Detection and Time-Frequency Analysis

使用string 容器翻转 字母

【视觉SLAM十四讲】第一章理论详解

仿牛客网讨论社区项目—项目总结及项目常见面试题

小心你的字典和样板代码

测试工具(四)Jenkins环境搭建与使用

leetcode125 Verify palindrome string

datagrip 报错 “The specified database userpassword combination is rejected...”的解决方法

滚动条样式修改

Srping bean in the life cycle
随机推荐
Jupyter shortcuts
Introduction to the basic principles, implementation and problem solving of crawler
仿牛客网项目总结
After the image is updated, Glide loading is still the original image problem
WebSocket实现聊天功能
A,H,K,N
MVVM project development (commodity management system 1)
Selenium: upload and download files
深度比较两个对象是否相同
LeetCode每日一题(309. Best Time to Buy and Sell Stock with Cooldown)
Talk about the bugs in using for in to traverse the array in js
JS的运行原理
小白的0基础教程SQL: 什么是SQL 01
Guest brush SQL - 2
Solve the problem of page flicker caused by browser scroll bars
Does flinkcdc have any solution for mysql's date field type conversion?
first unique character in characters
小白的0基础教程SQL: 关系数据库概述 02
仿牛客网讨论社区项目—项目总结及项目常见面试题
Dart 异常详解