当前位置: 代码迷 >> 综合 >> HDU-2031
  详细解决方案

HDU-2031

热度:76   发布时间:2023-11-27 03:56:41.0

在这里插入图片描述

import java.util.Scanner;public class Main {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);while (sc.hasNext()) {
    char[] set = {
    '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};int decimal = sc.nextInt(); //十进制数字int base = sc.nextInt(); //需要转换的进制int[] result = new int[1007];//处理负数if(decimal < 0) {
    System.out.print("-");decimal = -decimal;}int cnt = 0;while (decimal != 0){
    int temp = decimal % base;decimal = decimal / base;result[cnt++] = temp;}for (int i = cnt-1; i >= 0; i--) {
    System.out.print(set[result[i]]);}System.out.println();}}
}