当前位置:网站首页>M-ary to n-ary
M-ary to n-ary
2022-07-21 20:19:00 【Stewed radish】
Blog for the first time , Record the questions you usually do , In order to review and use in the future
This is a binary conversion problem , The code is as follows :
because 0-Z Only 36 Characters , So this question can only be in 36 Conversion within hexadecimal
The idea is to M Convert hexadecimal digits to decimal , Then convert the decimal system to N Base number
#include<iostream>
#include<string>
using namespace std;
void convert_MtoN(string a,int M,int N)
{
long long temp=0;
for(int i=0;i<a.length();i++)// First the a Convert to 10 Hexadecimal number
{
if(a[i]>='A' && a[i]<='Z')
{
temp*=M;
temp+=a[i]-'A'+10;
}
else if(a[i]>='0' && a[i]<='9')
{
temp*=M;
temp+=a[i]-'0';
}
else
{
cout<<" Illegal input !\n";
return;
}
}
if(N==10)// If it is converted to decimal, it will be output directly
cout<<temp;
else
{
if(temp==0)
cout<<0;
string b="";
int n=0;// Record the number of digits
while(temp>0)
{
b+=char(temp%N+'0');
temp/=N;
n++;
}
for(int i=n-1;i>=0;i--)
{
if(b[i]>'9')
cout<<char(b[i]-10+'A');
else
cout<<b[i];
}
}
}
int main()
{
// Example
string a="CAIXUKUN666";
//cin>>a;
convert_MtoN(a,36,10);
return 0;
}
边栏推荐
- 【记录】Optisystem运行卡死,无法点击关闭、输入变量数值等问题解决方法
- Idea2020 open run dashboard
- ES聚合统计语法
- Six relationships between UML models and classes
- 学习IO由浅入深
- 数据库删除emp_no重复的记录,只保留最小的id对应的记录
- ftp不能创建多级目录【循环创建问题】
- [PCB] Based on stm32f103rct6 joystick - Bluetooth module development board - drawing board notes sorting
- El radio value cannot be echoed
- [3D modeling] SolidWorks 3D modeling and prusaslicer slice printing learning notes
猜你喜欢
Jd.com's popular architect growth manual is launched, and you deserve the architect aura
Data consistency of Nacos registry cluster
As editor sets the indent position of the code on the right side of fluent development
PyTorch基础模块和实践
分布式事务其中的那些坑
学习IO由浅入深
NIO之Channel详解
In fastjason data type, there is a problem of $ref: "$.list[0]" when parsing jsonobject
合泰32-Onenet-WiFi模块-合泰单片机通过MQTT协议数据上云(一)
fastjson @JSONField format 不生效的原因
随机推荐
JSON tool class
self-attention注意力原理
4.paddlepaddle之10行代码mnist手写数字识别
Swagger的详细讲解及使用
Remove the spaces in the file names in batches and replace the spaces in the data stored in the database
Analysis of Nacos registry principle
Object copying tool class (fastjson)
[record] the operation of optisystem is stuck, and it is unable to click to close, input variable values and other solutions
微信公众号开发接入,利用微信公众平台申请测试号进行本地开发
Character function and memory function
Three paradigms of database design in MySQL
类加载器及双亲委派机制
OPT101单片光电二极管和单电源互阻放大器使用说明
isEmpty与 isBlank
MySql update语句或者delete语句 where条件没走索引会锁表
forms表单验证
Forms form validation
ftp不能创建多级目录【循环创建问题】
Nacos注册中心集群数据一致性问题
Web.Config自定义类的读取