在excel中有如下對的關係
A B C ......Z AA.....AZ BA....BZ............AAA................ZZZ..............
1..............26 27......52 53.....................703.................................
編寫函數 fun(String str ) 輸入第一行中的任意一個字符串,輸出對應的整數值。
第一行的字母(既excel表格中的列名)和第二行的數值(既對應的列數)是26進制和10進制的對應關係。
下面是自己寫了個更好點的代碼,希望大家共同商議.
protected static ArrayList<BigInteger> table=new ArrayList<BigInteger>();
static{
table.add(BigInteger.valueOf(0));
}
public static BigInteger fun(String strT){
int lon=strT.length();
BigInteger ResultT=(BigInteger)table.get(0);
for (int i = 0; i <lon; i++) {
char cha = strT.charAt(i);
ResultT =ResultT.add(BigInteger.valueOf((long) (Math.pow(26, lon-i-1) * ((int) cha - 64))));
table.add(ResultT);
}
return table.get(strT.length());
}