//产品思维啊,总不至于真要产品去敲代码吧(虽然代码比较简单)
public static void main(String[] args) {
//输入需要开发自行优化,是否可以采用流方式等。
Scanner sc = new Scanner(System.in);
int radix = sc.nextInt();
//传入的正整数是否会溢出,需要考虑产品是否会传入溢出级别的整数
int num = sc.nextInt();
//实现直接调用API实现,如果考场上真不会,可以抽出来作为函数用伪代码实现
//这里直接给出正确实现
String s = Integer.toString(num,radix);
//(由于java自带API只能变成小写字母,需要再调用API全部转大写)
s=s.toUpperCase();
//打印输出
System.out.println(s);
//测试代码,以及开发调试、防bug用的try-catch结构略。
} #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
//核心代码
void converPrint(unsigned int base,unsigned int num)
{
if(base<2 || base>19) return;
string str;
while(num){
char c;
c = num%base>9?num%base-10+'A':num%base+'0';
num /= base;
str += c;
}
reverse(str.begin(),str.end());
cout<<str<<endl;
}
//测试代码
int main()
{
converPrint(19,18);
return 0;
}
import java.util.Scanner; public class Main { public static void main(String[] args) { char[] charaters = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A','B', ' C','D', 'E', 'F', 'G', 'H', 'I'}; Scanner in = new Scanner(System.in); StringBuffer ans = new StringBuffer(""); int base = 0; int digit = 0; base = in.nextInt(); digit = in.nextInt(); if ((2 <= base) && (base <= 18)) { while (digit != 0) { ans.append(charaters[digit % base]); digit /= base; } ans = ans.reverse(); System.out.println(ans.toString()); } else { System.out.println("Input Error!"); } } }