当前位置:网站首页>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; }
边栏推荐
- D-Biotinol Involved by Biotin, CAS No: 53906-36-8 Specific Properties Description
- 【ROS2原理10】Interface数据的规定
- -Chess game-
- 初步认识对象
- Stanford CS143 速通PA1教程
- -Pickling peanuts-
- XSS详解及复现gallerycms字符长度限制短域名绕过
- C language structure, function and pointer exercise (simple address book)
- 改变社交与工作状态的即时通讯是什么呢?
- 最高月薪15K,谁有历经千辛万苦的意志,谁就能收获属于自己的成功~
猜你喜欢

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

03|Process Control

03|流程控制

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

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

Pagoda measurement - building LightPicture open source map bed system

商业模式及其 SubDAO 深入研究

Data storage - the C language

CAS:851113-28-5 (生物素-ahx-ahx-酪胺)

7. type( )函数——查询数据类型
随机推荐
y92.第六章 微服务、服务网格及Envoy实战 -- Envoy基础(三)
《痞子衡嵌入式半月刊》 第 60 期
Summary of basic operations of c language files
R语言使用glm函数构建逻辑回归模型(logistic)、使用subgroupAnalysis函数进行亚组分析并可视化森林图
7. type( )函数——查询数据类型
openEuler 知:abi 检测
你有对象类,我有结构体,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang结构体(struct)的使用EP06
微服务【同步和异步通讯详解】第6章
数据的存储——C语言
Docker 面试题2则--取数据库连接数和docker-compose
03|流程控制
生物素叠氮化物中的(CAS:1527486-16-3TAMRA-azide-PEG3-Biotin)反应的特点!
基于Web的疫情隔离区订餐系统
Next.js获取路由参数及styled-jsx 的使用
02| operator
C language structure, function and pointer exercise (simple address book)
Kubernetes YAML编写 讲解
-Pickling peanuts-
微信小程序tab切换时保存checkbox状态
【报错】ModuleNotFoundError: No module named ‘scp‘