当前位置:网站首页>M-ary number STR to n-ary number
M-ary number STR to n-ary number
2022-07-26 09:32:00 【Run away】
’0‘ - ’9‘ Express :0 - 9
‘a’ - ‘z’ Express :36 - 61
’A‘ - ’Z‘ Express :10 - 35
Input m Hexadecimal number str, Output n Hexadecimal number another
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
#include<ctime>
#include<utility>
#include<map>
#define ll long long
#define ld long double
#define ull unsigned long long
using namespace std;
const int INF = 0x3f3f3f3f3f;
const double eps = 1e-6;
const int maxn = 10000010;
char str[maxn],another[maxn];
int ten[maxn];
int switchToTen(int m);
void switchToAnother(int k,int n);
int main()
{
int m,n,k;
cin>>m>>n>>str;
k = switchToTen(m);
switchToAnother(k,n);
return 0;
}
int switchToTen(int m)
{
int i,j,len,k,c;
len = strlen(str);
k = 1;
memset(ten,0,sizeof(ten));
for(int i = 0;i<len;i++){
for(int j=0;j<k;j++){
ten[j] *= m;
}
if(str[i]>='0'&&str[i]<='9'){
ten[0] += str[i]-'0';
}
else if(str[i]>='A'&&str[i]<='Z'){
ten[0] += str[i]-'A'+10;
}
else if(str[i]>='a'&&str[i]<='z'){
ten[0] += str[i]-'a'+36;
}
for(int j=c=0;j<k;j++){
ten[j] += c;
if(ten[j]>=10){
c = ten[j] / 10;
ten[j] %= 10;
}
else c = 0;
}
while(c){
ten[k++] = c % 10;
c /= 10;
}
}
int temp;
for(int i=0,j=k-1;i<j;i++,j--){
temp = ten[i];
ten[i] = ten[j];
ten[j] = temp;
}
return k;
}
void switchToAnother(int k,int n)
{
int sum,r,t,d;
sum = 1;
r = 0;
memset(another,0,sizeof(another));
while(sum){
sum = 0;
for(int i=0;i<k;i++){
d = ten[i] / n;
sum += d;
if(i==k-1){
t = ten[i] % n;
if(t>=0&&t<=9){
another[r] = t+'0';
}
else if(t>=10&&t<=35){
another[r] = t-10+'A';
}
else another[r] = t-36+'a';
r++;
}
else{
ten[i+1] += ten[i]%n * 10;
}
ten[i] = d;
}
}
for(int i=r-1;i>=0;i--){
printf("%c",another[i]);
}
printf("\n");
}
边栏推荐
- VS2019配置opencv
- php执行shell脚本
- 2022 chemical automation control instrument operation certificate test question simulation test platform operation
- “互联网+”时代的现代医学
- asp.net 使用redis缓存
- JS output diamond on the console
- 大二上第二周学习笔记
- Source code analysis of object wait notify notifyAll
- Implementation of fragment lazy loading after multi-layer nesting
- RMQ学习笔记
猜你喜欢

After attaching to the process, the breakpoint displays "currently will not hit the breakpoint, and no symbols have been loaded for this document"

2022 mobile crane driver test question simulation test question bank simulation test platform operation

2019 ICPC Asia Yinchuan Regional(水题题解)

会议OA项目(三)---我的会议(会议排座、送审)

Jmeter配置元件之CSV数据文件设置

Drawing shadow error diagram with MATLAB

el-table实现增加/删除行,某参数跟着变

js中树与数组的相互转化(树的子节点若为空隐藏children字段)

matlab中的AR模型短时预测交通流

配置ADCS后访问certsrv的问题
随机推荐
【Flutter -- 布局】Align、Center、Padding 使用详解
解决IE7 & IE8 存储cookie问题
Fiddler抓包工具之移动端抓包
js中树与数组的相互转化(树的子节点若为空隐藏children字段)
cocoapods的安装和使用
2020-12-29
docker配置mysql集群
附加到进程之后,断点显示“当前不会命中断点 还没有为该文档加载任何符号”
调用DLL开启线程的问题
神经网络与深度学习-6- 支持向量机1 -PyTorch
“互联网+”时代的现代医学
Your login IP is not within the login mask configured by the administrator
Basic use of ArcGIS 1
C# 托管与非托管
系统安装Serv-U后IIS出错提示:HRESULT:0x80070020
wap端微信h5支付,用于非微信浏览器
How to add a PDB
自定义密码输入框,无圆角
ZXing简化版,转载
字节缓冲流&字符流详解