当前位置:网站首页>3438. 数制转换
3438. 数制转换
2022-08-10 00:30:00 【NEFU AB-IN】
Powered by:NEFU AB-IN
文章目录
3438. 数制转换
题意
求任意两个不同进制非负整数的转换(2 进制 ∼ 16 进制),所给整数在 int 范围内。
不同进制的表示符号为(0,1,…,9,a,b,…,f)或者(0,1,…,9,A,B,…,F)思路
手写两个函数,分别是 整数转字符,字符转整数
其余正常写就行代码
/* * @Author: NEFU AB-IN * @Date: 2022-08-08 00:33:59 * @FilePath: \Acwing\3438\test.cpp * @LastEditTime: 2022-08-09 20:29:03 */ #include <bits/stdc++.h> using namespace std; #define int long long #define SZ(X) ((int)(X).size()) #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define DEBUG(X) cout << #X << ": " << X << endl; typedef pair<int, int> PII; const int INF = INT_MAX; const int N = 1e6 + 10; char itoc(int x) { if (x < 10) return '0' + x; return 'A' + x - 10; } int ctoi(char c) { if (c <= '9') return c - '0'; if (c <= 'Z') return c - 'A' + 10; return c - 'a' + 10; } signed main() { IOS; string n; int a, b; cin >> a >> n >> b; // a进制转10进制 int ans = 0; for (auto i : n) { ans = ans * a + ctoi(i); } // 10进制转b进制 string res; while (ans) { res += itoc(ans % b); ans /= b; } reverse(res.begin(), res.end()); cout << res << '\n'; return 0; }
边栏推荐
猜你喜欢

flask——请求、响应、请求扩展、session、闪现、蓝图、g对象、flask-session

Docker interview question 2--get the number of database connections and docker-compose

【CAS:41994-02-9 |Biotinyl tyramide】Biotinyl tyramide price

Solidity最强对手:MOVE语言及新公链崛起

XSS高级 svg 复现一个循环问题以及两个循环问题

3.4 - 编译与解释 3.5 - 编译过程 3.8 - 文法

嵌入式Qt-实现两个窗口的切换

【kali-密码攻击】(5.1.2)密码在线破解:Medusa

pytest:如何在测试中编写和报告断言

RedHat红帽RHEL7安装与使用,VMware Workstation16 Pro虚拟机的安装与使用
随机推荐
Enhanced Deep Residual Networks for Single Image Super-Resolution
由生物素参与的D-Biotinol,CAS号:53906-36-8具体特性说明
Moonbeam网络维护模式(Maintenance Mode)解读
宝塔实测-搭建LightPicture开源图床系统
flask——请求、响应、请求扩展、session、闪现、蓝图、g对象、flask-session
CVPR22 Oral|通过多尺度token聚合分流自注意力,代码已开源
[obs] obsqsv11 hard coding and comparison with metartc codec
2022金九银十工作潮,怎么样才能成功跳槽面试拿到高薪呢?
Quick responsiveness intelligent/smart responsiveness of polyethylene glycol type nano/reduction response hydrogels research and preparation
Leetcode83. 删除排序链表中的重复元素
地雷数量求解
el-input保留一位小数点
你有对象类,我有结构体,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang结构体(struct)的使用EP06
Interlay集成至Moonbeam,为网络带来interBTC和INTR
手把手教你编写性能测试用例
D-Biotinol Involved by Biotin, CAS No: 53906-36-8 Specific Properties Description
Involved in PEG-Biotin (CAS: 1778736-18-7) Biotin-PEG4-OH is widely used in molecular target detection
GBJ1510-ASEMI机器人电源整流桥GBJ1510
-向量点积-
c语言结构体、函数以及指针练习(简单通讯录)