首页 > 试题广场 >

进制转换

[编程题]进制转换
  • 热度指数:34910 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
给定一个十进制数M,以及需要转换的进制数N。将十进制数M转化为N进制数

输入描述:
输入为一行,M(32位整数)、N(2 ≤ N ≤ 16),以空格隔开。


输出描述:
为每个测试实例输出转换后的数,每个输出占一行。如果N大于9,则对应的数字规则参考16进制(比如,10用A表示,等等)
示例1

输入

7 2

输出

111
头像 阿贝尔的日记
发表于 2022-09-07 22:10:18
进制转换 进制转换 通过模N除N可以按N进制一位一位取下来,并去arr里面找对应的字符串加起来。 需要考虑到M为负数的情况,M为0的情况。 #include <iostream> #include <string> #include <algorithm> usi 展开全文
头像 星不离月
发表于 2022-10-13 09:46:51
import java.util.Scanner; public class Main {     public static void main(String[] args)& 展开全文
头像 牛马ID
发表于 2022-05-28 17:44:45
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { int n,b; string res, table = "012345 展开全文
头像 bao_hu_yuan_zhang
发表于 2024-03-20 21:27:09
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { int M=0; int N=0; cin> 展开全文
头像 牛客541017438号
发表于 2024-09-27 18:07:51
import re import sys inputs = [] for line in sys.stdin: inputs.extend(list(map(int, line.split()))) def transfer_them(source, target): 展开全文
头像 bandiaoz
发表于 2024-12-26 16:17:23
解题思路 这是一道进制转换题目,主要思路如下: 问题分析: 输入一个十进制数 输入目标进制 ( ) 需要处理负数情况 需要处理16进制的字母表示 解决方案: 使用除N取余法 倒序保存余数 处理负数符号 使用字符数组映射16进制 实现细节: 特判0的情况 处理负数 使用字符 展开全文
头像 我fo慈悲
发表于 2023-05-11 01:51:52
#include <iostream> #include<string> #include<algorithm> using namespace std; int main() { string s,table="0123456789ABCDEF"; 展开全文
头像 秋招能不能有个offer
发表于 2022-07-13 20:01:55
m, n = map(int, input().split()) res = [] a = [0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F'] # 十六进制 if m&n 展开全文
头像 一城烟雨柳色青
发表于 2023-02-05 22:03:21
#include <algorithm> #include <asm-generic/errno.h> #include <iostream> #include <vector> #include <string> using namesp 展开全文
头像 喜欢可抵岁月漫长
发表于 2023-06-25 17:26:58
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new S 展开全文