hdu 2100 Lovekey

import java.math.BigInteger;
import java.util.Scanner;

 


public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub   
       
        init(200);
       
        String tmpStr;
        char[] ch1, ch2;
        Scanner cin = new Scanner(System.in);
       
        while(cin.hasNext()) {
            tmpStr = cin.next();
            ch1 = tmpStr.toCharArray();
            tmpStr = cin.next();
            ch2 = tmpStr.toCharArray();
           
            BigInteger a = BigInteger.ZERO;
            BigInteger b = BigInteger.ZERO;
           
            int i, len = ch1.length;
            for(i = 0; i < len; i++) {               
                long t = (long)ch1[i] - 'A';
                a = a.add(BigInteger.valueOf(t).multiply(pow26[len - i - 1]));
            }
           
            len = ch2.length;
            for(i = 0; i < len; i++) {
                long t = (long)ch2[i] - 'A';
                b = b.add(BigInteger.valueOf(t).multiply(pow26[len - i - 1]));
            }
           
            a = a.add(b);
            tmpStr = a.toString(26);
        //    System.out.println("a=" + a + " " + "tmpStr=" + tmpStr);
            ch1 = tmpStr.toCharArray();
           
            len = ch1.length;
            for(i = 0; i < len; i++) {
                if('a' <= ch1[i] && ch1[i] <= 'z')
                ch1[i] = (char)(ch1[i] - 'a' + 58);
            }
            for(i = 0; i < len; i++) {
                System.out.print((char)(ch1[i] - '0' + 'A'));
            }
            System.out.println();
        }
    }
   
    public static void init(final int n) {
        BigInteger big26 = BigInteger.valueOf(26);
        pow26[0] = BigInteger.ONE;
        for(int i = 1; i <= n; i++) {
            pow26[i] = pow26[i - 1].multiply(big26);
        }
    }
   
    static final BigInteger[] pow26 = new BigInteger[210];
}

posted @ 2010-10-31 15:03  菜到不得鸟  阅读(169)  评论(0)    收藏  举报