当前位置:网站首页>3438. 数制转换
3438. 数制转换
2022-07-17 21:50:00 【Ray.C.L】

思路:将a进制数number转化为10进制(秦九韶),再用短除法转为b进制
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
char itoc(int x){
if(x < 10) return '0' + x;
return 'A' + x - 10;
}
int ctoi(char x){
if(x <= '9') return x - '0';
if(x <= 'Z') return x - 'A' + 10;
return x - 'a' + 10;
}
int main()
{
int n, a, b;
string number;
cin >> a >> number >> b;
n = 0;
for(auto c : number) n = n * a + ctoi(c);
string res;
while(n) res += itoc(n % b) , n /= b;
reverse(res.begin(), res.end());
cout << res << endl;
return 0;
}
边栏推荐
- Win10 Microsoft Store打不开(开启TLS 1.2)
- MySQL index (III)
- Common built-in functions, iteratable objects, iterator objects, exception capture, purpose of exception capture, generator objects, modules, absolute and relative imports, package concepts, modules
- Alibaba microservice component Nacos registry
- Pyside2 drawing embedded in Matplotlib
- ospf-LSA
- Use tongweb's hot deployment function with caution
- Huawei wireless device configuration intelligent roaming
- dba
- Learning records [email protected] Moveactivityidto task fallback special case analysis
猜你喜欢

How to quickly realize Zadig single sign on on authoring?

Huawei wireless device configuration dynamic load balancing

滑動窗口最大值問題

慎用TongWeb的热部署功能

Win10 Microsoft Store cannot be opened (enable TLS 1.2)

论文阅读 TEMPORAL GRAPH NETWORKS FOR DEEP LEARNING ON DYNAMIC GRAPHS

Zhikanghu property elderly care service plan

Gradle introduction notes

Database SQL Server

【萌新解题】四数之和
随机推荐
C. Watto and mechanism (hash | dictionary tree + DFS (DFS on tree))
LabVIEW uses multithreading. Will the program run faster
An unforgettable day in 2022 summer camp
MySQL view
抽象类与派生类
Analysis of network communication flow of different containers on the same host
Comparaison de deux types de machines virtuelles
滑动窗口最大值问题
Gradle introduction notes
Redis source code and design analysis -- 2 Linked list
CMAKE学习笔记
Dr. Tao's lunar line reverses by 6.0
Abstract classes and derived classes
Code Runner for VS Code,下载量突破 4000 万!支持超过50种语言
CF 807 E. Mark and Professor Koro(权值线段树)
MySQL read / write separation
详解C语言动态内存管理
The first step of agile: turn "iteration" into "sprint" and start!
慎用TongWeb的热部署功能
SQL related time date type