当前位置:网站首页>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; }
边栏推荐
- Characteristics of the (CAS:1527486-16-3TAMRA-azide-PEG3-Biotin) reaction in biotin azide!
- 微信公众号如何开通支付功能?
- Xi'an biotin-tetrapolyethylene glycol-amide-4phenol light yellow semi-solid
- How to turn off system protection in Win11?How to turn off the system protection restore function?
- 嵌入式Qt-实现两个窗口的切换
- Leetcode82. 删除排序链表中的重复元素 II
- 输入的这些数是否对称
- Biotin-Cy2 Conjugate,生物素-Cy2 偶联物_Cy2 生物素偶联物
- 3.9 - 正规表达式和正规集 3.10 - 有限自动机
- Stanford CS143 速通PA1教程
猜你喜欢
随机推荐
地雷数量求解
最高月薪15K,谁有历经千辛万苦的意志,谁就能收获属于自己的成功~
数据建模已死,真的吗?
R语言使用glm函数构建logistic回归模型,使用forestmodel包的forest_model函数可视化逻辑回归模型对应的森林图
【kali-密码攻击】(5.2.1)密码分析:Hash Identifier(哈希识别)
-red and black-
基于Web的疫情隔离区订餐系统
【Django】缓存
Docker 面试题2则--取数据库连接数和docker-compose
Biotin-Cy2 Conjugate,生物素-Cy2 偶联物_Cy2 生物素偶联物
宽带由20M换为100M
Win11怎么关闭系统保护功能?系统保护还原功能怎么关闭?
-Vector Dot Product-
abicc 知:API compatibility report 介绍
【无标题】
20220808-一些想法
嵌入式Qt-实现两个窗口的切换
你有对象类,我有结构体,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang结构体(struct)的使用EP06
What should I do if there is no sound after reinstalling the system in win10?
GBJ1510-ASEMI机器人电源整流桥GBJ1510