当前位置:网站首页>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; }
边栏推荐
- 西安生物素-四聚乙二醇-酰胺-4苯酚 浅黄色半固态
- How to turn off system protection in Win11?How to turn off the system protection restore function?
- Enhanced Deep Residual Networks for Single Image Super-Resolution
- Solidity最强对手:MOVE语言及新公链崛起
- abicc 知:API compatibility report 介绍
- Next.js获取路由参数及styled-jsx 的使用
- Fedora 36 dnf 安装ModSecurity和 OWASP 核心规则集
- 渗透测试与攻防对抗——漏洞扫描&逻辑漏洞(Part1)
- pytest:如何在测试中编写和报告断言
- CVPR22 Oral|通过多尺度token聚合分流自注意力,代码已开源
猜你喜欢
随机推荐
Pyscript,创建一个能执行crud操作的网页应用
03|Process Control
Leetcode80. 删除有序数组中的重复项 II
365 days challenge LeetCode1000 questions - Day 052 Step by step summation to get the minimum value of positive numbers Greedy
这一次,话筒给你:向自由软件之父 Richard M. Stallman 提问啦!
Docker interview question 2--get the number of database connections and docker-compose
你有对象类,我有结构体,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang结构体(struct)的使用EP06
嵌入式Qt-实现两个窗口的切换
Solidity最强对手:MOVE语言及新公链崛起
温度响应性纳米水凝胶光子品体/纤维素修饰荧光水凝胶/载脂质体水凝胶的制备方法
Win7怎么把控制面板添加到右键菜单
西安生物素-四聚乙二醇-酰胺-4苯酚 浅黄色半固态
3.11-程序基本的控制语句 3.12-表达式 3.13-数据类型 3.14-常量/变量 3.15-标识符
2022金九银十工作潮,怎么样才能成功跳槽面试拿到高薪呢?
-Vector Dot Product-
R语言使用cox函数构建生存分析回归模型、使用subgroupAnalysis进行亚组分析并可视化森林图
开发IM即时通讯容易吗?需要什么技术
eyb:Redis学习(4)
XSS详解及复现gallerycms字符长度限制短域名绕过
PEG 衍生物Biotin-PEG1-OH(cas:95611-10-2,2-生物素氨基乙醇)优势说明