当前位置:网站首页>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; }
边栏推荐
- Biotin-Cy2 Conjugate,生物素-Cy2 偶联物_Cy2 生物素偶联物
- 【Django】缓存
- 最高月薪15K,谁有历经千辛万苦的意志,谁就能收获属于自己的成功~
- Xi'an biotin-tetrapolyethylene glycol-amide-4phenol light yellow semi-solid
- Docker 面试题2则--取数据库连接数和docker-compose
- Win7怎么把控制面板添加到右键菜单
- -Knight Parade-
- 数据建模已死,真的吗?
- Involved in PEG-Biotin (CAS: 1778736-18-7) Biotin-PEG4-OH is widely used in molecular target detection
- 移动终端数据业务高安全通信方案研究
猜你喜欢
改变社交与工作状态的即时通讯是什么呢?
2022金九银十工作潮,怎么样才能成功跳槽面试拿到高薪呢?
即时通讯开发如何撸一个WebSocket服务器
嵌入式Qt-实现两个窗口的切换
D-Biotinol Involved by Biotin, CAS No: 53906-36-8 Specific Properties Description
MySQL最大连接数限制如何修改
PEG derivative Biotin-PEG1-OH (cas: 95611-10-2, 2-biotinaminoethanol) advantage description
收银管理软件如何做好员工管理?
数据的存储——C语言
Solidity最强对手:MOVE语言及新公链崛起
随机推荐
【Django】缓存
Docker interview question 2--get the number of database connections and docker-compose
使用 GoogleTest 框架对 C 代码进行单元测试
Solidity最强对手:MOVE语言及新公链崛起
Quick responsiveness intelligent/smart responsiveness of polyethylene glycol type nano/reduction response hydrogels research and preparation
Pagoda measurement - building LightPicture open source map bed system
C语言头文件组织与包含原则
D-Biotinol Involved by Biotin, CAS No: 53906-36-8 Specific Properties Description
Redis redisTemplate.execute 执行锁
-Vector Dot Product-
有PEG-Biotin参与的(CAS:1778736-18-7)Biotin-PEG4-OH广泛用于分子靶点检测
CAS:183896-00-6 (Biotin-PEG3-C3-NH2) PEG derivative
Xi'an biotin-tetrapolyethylene glycol-amide-4phenol light yellow semi-solid
XSS详解及复现gallerycms字符长度限制短域名绕过
-red and black-
y92.第六章 微服务、服务网格及Envoy实战 -- Envoy基础(三)
win10重装系统后没声音怎么办?
365天挑战LeetCode1000题——Day 052 逐步求和得到正数的最小值 贪心
Kubernetes YAML编写 讲解
什么是一网统管?终于有人讲明白了