当前位置:网站首页>Noi / 1.5.25: finding special natural numbers
Noi / 1.5.25: finding special natural numbers
2022-04-22 07:14:00 【InTheSolitude】
NOI / 1.5 Cycle control of programming basis 25: Find a special natural number
describe
- A decimal natural number , Its seven and nine decimal representations are three digits , And the order of the three digit numbers of the seventh and ninth system is just the opposite . Program to find this natural number , And output the display .
Input
- nothing .
Output
- Three elements :
The first line is the decimal representation of this natural number ;
The second line is the hexadecimal representation of this natural number ;
The third line is the hexadecimal representation of this natural number . - ac Code
#include<iostream>
#include<cmath>
using namespace std;
int seventoten(int n){
int r=0,i=0,t;
while(n){
t=n%10;
n/=10;
r+=t*pow(7,i);
i++;
}
return r;
}
int reverse(int n){
int r=0,i=0,t=n,mask=1;
while(t>9){
t/=10;
mask*=10;
}
while(n){
t=n%10;
r+=t*mask;
mask/=10;
n/=10;
}
return r;
}
int tentonine(int n){
int r=0,t,i=1;
while(n){
t=n%9;
r+=t*i;
i*=10;
n/=9;
}
return r;
}
int tentoseven(int n){
int r=0,t,i=1;
while(n){
t=n%7;
r+=t*i;
i*=10;
n/=7;
}
return r;
}
int main()
{
int h,i,j;
for(h=100;h<1000;h++){
i=tentoseven(h);
j=tentonine(h);
if(i==reverse(j)){
cout<<h<<endl;
cout<<i<<endl;
cout<<j<<endl;
break;
}
}
}
Ideas
- Two binary conversion functions , One reverse function
- There is a loophole : How to determine the range when retrieving from decimal numbers ? How to make sure it's three digits , Here's the loop 100 It's a magic number
If you have better ideas and suggestions, please leave a message to me in the comment area. Thank you for your visit !
版权声明
本文为[InTheSolitude]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220609347029.html
边栏推荐
- 集成电路模拟版图入门-版图基础学习笔记(二)
- Nacos persistent switch configuration
- 【SVN】Subversion安装使用笔记
- 泛型与反射的实际使用练习(包含一个泛型缓存)----手写ORM框架
- Introduction to IC Analog Layout - learning notes on layout Basics (I)
- 分布式任务调度与计算框架:PowerJob 高级特性-OpenAPI 04
- Distributed task scheduling and computing framework: powerjob advanced features - container 03
- 实验室安全考试
- 如何成为IC验证工程师?
- 短路
猜你喜欢

数字ic设计有前途吗?职业发展,薪资待遇如何?

Start with stm32f4 floating point operation (FPU) function + use DSP Library

软件工程导论第六版复习(笔记)

【Bug小记】input:-webkit-autofill:输入框自动填充背景问题

ASP.NET日常开发随手记------iis服务器支持下载apk

微信第三方网页授权

Nacos命名空间分组和DataID三者关系

Quantify PM2 in 5 cities 5 changes over time

First order digital low-pass filter - C language / Matlab implementation

Powerjob workflow
随机推荐
Comparison and improvement of Nacos service registration center
leetcode598:范围求和II
Fields in uppercase accept the final initial but become lowercase
Random库的8个函数
Leetcode598: range summation II
Distributed task scheduling and computing framework: powerjob advanced features - OpenAPI 04
leetcode打卡日记 day 01
MySQL完全卸载,mysql服务清理
【JEECG】修改Viser图表颜色样式
Powerjob workflow
pyautocad 选择对象报错的解决方案
Distributed task scheduling and computing framework: powerjob quick start (local ide version) 02
leetcode1218:最长定差子序列
Nacos cluster architecture
ASP.NET日常开发随手记------发送邮件
Nacos持久化切换配置
如何成为IC验证工程师?
Alibaba cloud's deployment of rsshub stepping on the pit notes
Changes in the number of different types of calls in different months in 911 data
Leetcode punch in