题解 | #进制转换#
进制转换
http://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main{
private static Map<Character,Integer> map = new HashMap<Character,Integer>(){{
put('a',10);
put('b',11);
put('c',12);
put('d',13);
put('e',14);
put('f',15);
}};
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
String str = sc.nextLine().toLowerCase().substring(2);
int n = str.length()-1;
long sum = 0;
for(int i =n;i>=0;i--){
char chr = str.charAt(i);
if(map.keySet().contains(chr)){
sum += map.get(chr) * Math.pow(16,n-i);
}else{
sum += Integer.valueOf(String.valueOf(str.charAt(i))) * Math.pow(16,n-i);
}
}
System.out.println(sum);
}
}