进制转换,java做
StringBuffer 的方法中setCharAt(int,char)可以改变其某位的字符
View Code
import java.io.*;import java.util.*;import java.math.*;public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); while (cin.hasNext()) { String st = cin.next(); int a = cin.nextInt(); int b = cin.nextInt(); BigInteger bigA = new BigInteger(st, a); StringBuffer ans = new StringBuffer(bigA.toString(b)); if (ans.length() > 7) { System.out.println(" ERROR"); continue; } for (int i = 0; i < ans.length(); i++) if (ans.charAt(i) <= 'z' && ans.charAt(i) >= 'a') ans.setCharAt(i, (char)('A' - 'a' + ans.charAt(i))); int len = ans.length(); for (int i = len; i < 7; i++) ans.insert(0, ' '); System.out.println(ans.toString()); } }}