杭電oj--2031
阿新 • • 發佈:2018-11-11
import java.util.Scanner;
public class Main { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); char arr[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; while (scanner.hasNext()) { StringBuilder sb = new StringBuilder(); boolean flag = false;// 預設不是負數 int N = scanner.nextInt(); int R = scanner.nextInt(); if (N < 0) { N = -N; flag = true; } do { sb.append(arr[N % R]); N /= R; } while (N != 0); if(flag) System.out.print("-"); System.out.println(sb.reverse()); }
} }