当前位置:网站首页>数制转换(暑假每日一题 16)
数制转换(暑假每日一题 16)
2022-08-05 16:43:00 【sweetheart7-7】
求任意两个不同进制非负整数的转换( 2 2 2 进制 ∼ 16 16 16 进制),所给整数在 i n t int int 范围内。
不同进制的表示符号为 ( 0 , 1 , … , 9 , a , b , … , f ) (0,1,…,9,a,b,…,f) (0,1,…,9,a,b,…,f)或者 ( 0 , 1 , … , 9 , A , B , … , F ) (0,1,…,9,A,B,…,F) (0,1,…,9,A,B,…,F)
输入格式
输入只有一行,包含三个整数 a , n , b a,n,b a,n,b。 a a a 表示其后的 n n n 是 a a a 进制整数, b b b 表示欲将 a a a 进制整数 n n n 转换成 b b b 进制整数。
a , b a,b a,b 是十进制整数。
数据可能存在包含前导零的情况。
输出格式
输出包含一行,该行有一个整数为转换后的 b b b 进制数。
输出时字母符号全部用大写表示,即 ( 0 , 1 , … , 9 , A , B , … , F ) (0,1,…,9,A,B,…,F) (0,1,…,9,A,B,…,F)。
数据范围
2 ≤ a , b ≤ 16 , 2≤a,b≤16, 2≤a,b≤16,
给定的 a a a 进制整数 n n n 在十进制下的取值范围是 [ 1 , 2147483647 ] [1,2147483647] [1,2147483647]。
输入样例:
15 Aab3 7
输出样例:
210306
#include<iostream>
using namespace std;
int a, b;
string s;
int get(char & c){
if('0' <= c && c <= '9') return c - '0';
return tolower(c) - 'a' + 10;
}
int getTen(int a, string s){
int res = 0;
for(int i = 0; i < s.size(); i++)
res = res * a + get(s[i]);
return res;
}
string trans(int n, int b){
string res;
char c;
while(n){
int x = n % b;
if(x < 10) c = x + '0';
else c = 'A' + (x - 10);
res = c + res;
n /= b;
}
return res;
}
int main(){
cin >> a >> s >> b;
int x = getTen(a, s);
cout << trans(x, b) << endl;
return 0;
}
边栏推荐
- Sentinel链路模式规则无效
- 远程push记录:
- 傅里叶变换
- Study Notes 227—Word automatic catalog, there is a space after the catalog number, how can I set it to remove it?
- UVa1149 - Bin Packing
- 安装特定指定版本 低版本的r包 r包降级
- 【计算讲谈社】第七讲|AI 的价值探索:如何拓展商业边界?
- Study Notes 238—How to quickly enter various root signs in a word document [No numbers are entered under the root sign, and a dashed box will not appear]
- leetcode:285. 二叉搜索树中的中序后继节点
- 华为设备Smart Link和Monitor Link配置命令
猜你喜欢
随机推荐
[Case] A rotating circle in 3d transformation
基于consul的服务注册与消费案例
consul安装
【Case】Animation animation
基于eureka-server的服务注册与消费案例
三菱FX3U PLC模拟量输出FB (FX2N-4DA)
[极角排序 扫描法]UVa1606 - Amphiphilic Carbon Molecules
流行的 Web 框架安全性比较
【翻译】EF Core 3.1.x, 5.x & 6.x Second Level Cache Interceptor
西气东输年输气量首超千亿立方米,图扑助力管道监控
数据思维总结:
MYSQL(进阶篇)——一篇文章带你深入掌握MYSQL
机器视觉应用方向及学习思路总结
laravel 子查询
小伙伴面试之成都创宇知道
求先序排列
安装特定指定版本 低版本的r包 r包降级
Good code in the eyes of a compiler engineer: Loop Interchange
EasyCVR calls the stop real-time recording interface, how to solve the problem that the recording address is not returned?
程序员35岁之后不写程序了,该怎样职业规划?

![[Case] A rotating circle in 3d transformation](/img/da/91f5050deb5c72a1527b5a88160e6c.png)







