题目地址: http://poj.org/problem?id=1220
import java.util.*;
import java.math.*;
import java.text.*;
import java.io.*;public class Main
{public static int getNum(char ch){if(Character.isDigit(ch)) return ch-'0';else if(Character.isUpperCase(ch)) return ch-'A'+10;else if(Character.isLowerCase(ch)) return ch-'a'+36;return 0;}public static char getChar(int i){if(i>=0&&i<=9) return (char)(i+'0');else if(i>=10&&i<=35) return (char)(i+'A'-10);else if(i>=36) return (char)(i+'a'-36);return '0';}public static void main(String[] args) {Scanner cin = new Scanner(new BufferedInputStream(System.in));int T=cin.nextInt();while(T--!=0){int base1=cin.nextInt(),base2=cin.nextInt();String s=cin.next();BigInteger n = BigInteger.ZERO;for(int i=0;i<s.length();i++){char ch=s.charAt(i);n = n.multiply(n.valueOf(base1)).add(n.valueOf(getNum(ch)));}String ans = new String();while(!n.equals(BigInteger.ZERO)) {ans=getChar(n.mod(n.valueOf(base2)).intValue())+ans;n=n.divide(n.valueOf(base2));}if(ans.length()==0) ans+='0';System.out.println(base1+" "+s);System.out.println(base2+" "+ans);System.out.println();}}
}