当前位置:网站首页>m进制数str转n进制数
m进制数str转n进制数
2022-07-26 09:29:00 【逃夭丶】
’0‘ - ’9‘表示:0 - 9
‘a’ - ‘z’ 表示:36 - 61
’A‘ - ’Z‘表示:10 - 35
输入m进制数str,输出n进制数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");
}
边栏推荐
- QT随手笔记(六)——更新界面、截图、文件对话框
- Bloom filter
- Force deduction brush questions, sum of three numbers
- VS2019配置opencv
- 搜索模块用例编写
- asp.net 使用redis缓存(二)
- Android implements the caching mechanism and caches multiple data types
- docker配置mysql集群
- Malloc failed to allocate space and did not return null
- Custom password input box, no rounded corners
猜你喜欢

2022 Shanghai safety officer C certificate examination questions and mock examination

Windows通过命令备份数据库到本地

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

Elastic APM installation and use

Basic use of Arc GIS 2

2022 chemical automation control instrument operation certificate test question simulation test platform operation
![[Online deadlock analysis] by index_ Deadlock event caused by merge](/img/67/0a02ad248c3ab21d3240e12aa23313.png)
[Online deadlock analysis] by index_ Deadlock event caused by merge

性格测试系统v1.0

Does volatile rely on the MESI protocol to solve the visibility problem? (top)

After attaching to the process, the breakpoint displays "currently will not hit the breakpoint, and no symbols have been loaded for this document"
随机推荐
V-for dynamically sets the SRC of img
The difference between thread join and object wait
大二上第一周学习笔记
微信小程序学习笔记2
选择器的使用
什么是异步操作
keepalived 实现mysql自动故障切换
【Mysql数据库】mysql基本操作集锦-看得会的基础(增删改查)
How to add a PDB
asp.net 使用redis缓存
微信小程序开发
简单行人重识别代码到88%准确率 郑哲东 准备工作
暑假第四周
Audio and video knowledge
v-premission添加权限
音视频知识
arcgis的基本使用1
(二)面扫描仪与机械臂的手眼标定(眼在手外:九点标定)
解决“NOTE: One or more layouts are missing the layout_width or layout_height attributes.”
Windows backs up the database locally by command