当前位置: 首页 > news >正文

高精度进制转换

#include <bits/stdc++.h>
using namespace std;int val(char c) { // 字符转值if (c >= '0' && c <= '9') return c - '0';if (c >= 'A' && c <= 'Z') return c - 'A' + 10;return c - 'a' + 36;
}char digitChar(int v) { // 值转字符if (v < 10) return '0' + v;if (v < 36) return 'A' + (v - 10);return 'a' + (v - 36);
}void mul(vector<int>& a, int m) { // 高精乘int carry = 0;for (int i = 0; i < (int)a.size(); i++) {int t = a[i] * m + carry;a[i] = t % 10;carry = t / 10;}while (carry) {a.push_back(carry % 10);carry /= 10;}
}void add(vector<int>& a, int v) { // 高精加int carry = v;for (int i = 0; i < (int)a.size(); i++) {int t = a[i] + carry;a[i] = t % 10;carry = t / 10;if (!carry) return;}while (carry) {a.push_back(carry % 10);carry /= 10;}
}int divi(vector<int>& a, int d) { // 高精除int r = 0;for (int i = (int)a.size() - 1; i >= 0; i--) {int t = r * 10 + a[i];a[i] = t / d;r = t % d;}while (a.size() > 1 && a.back() == 0)a.pop_back();return r;
}int main() {ios::sync_with_stdio(0),cin.tie(0);int x, y;string z;cin >> x >> y >> z;vector<int> value(1, 0);// x进制转十进制for (char c : z) {int d = val(c);mul(value, x);   // value = value * xadd(value, d);   // value += d}if (value.size() == 1 && value[0] == 0) {// 特判0cout << 0;return 0;}// 十进制转y进制string out;while (!(value.size() == 1 && value[0] == 0)) {int r = divi(value, y);   // value /= yout.push_back(digitChar(r));}reverse(out.begin(), out.end());cout << out;
}
http://www.rkmt.cn/news/54703.html

相关文章:

  • AI元人文:赋能技术人文深度融合的法治新范式
  • [K8s/资源调度] Vocano : 开源的 Kubernetes 批处理系统
  • 2025 Super MB Pro M6+ PRO: BENZ BMW 2-in-1 Diagnostic Tool with Panasonic FZ-G1 Tablet Ready to Use
  • 11.19 p1115最大字段和
  • 20232419 2025-2026-1 《网络与系统攻防技术》实验六实验报告
  • 22年副省daan
  • 第30天(中等题 二分查找)
  • 腾讯云ubuntu服务器初始化
  • 现实的一切,都是自指自洽的道德因果逻辑态
  • Firefox扩展界面优化与浏览器技术更新
  • 11月19日日记
  • 代码随想录Day15_二叉树
  • 什么是代币?从ERC-20开始 - all-in
  • Yanhua Mini ACDP-2 BMW CAS Package: Advanced CAS ISN Module Programming for N20/N55/B38
  • 发布与订阅者模式-复盘
  • 20232307 2025-2026-1 《网络与系统攻防技术》实验七实验报告
  • 《R语言医学数据分析实战》学习记录--第一章 R语言介绍
  • 李克特量表(Likert scale)
  • java---maven
  • 状语从句学案
  • 用 Rust 与 Tesseract 进行英文数字验证码识别
  • contig 和 scaffold的区别和联系
  • linux ftp脚本
  • Yanhua Mini ACDP-2 BMW ECU Package: EUC Clone License with Modules 3/8/27 Bench Interface Board
  • [Python刷题记录]-搜索插入位置-二分查找-简单
  • 告别低效备考!2025雅思封闭班培训机构深度测评
  • mariadb galera集群在Openstack中的应用 - T
  • linux ftp慢
  • 2025年11月水泵,多级水泵,消防水泵公司推荐:扬程适配性与能效等级测评
  • linux ftp同步