在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());
}