只需要按照16进制转10进制的方法写代码实现就行了,具体如下:
public class Main {
private static int[] num = {10, 11, 12, 13, 14, 15, 16};
private static int[] poe = {0, 1, 2};
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int res = 0;
while (in.hasNextLine()) {
String str = in.nextLine();
int len = str.length();
for (int i = len - 1; i > 1 ; i --) {
if (str.charAt(i) >= 'A' && str.charAt(i) <= 'F') {
res += num[str.charAt(i) - 'A'] * Math.pow(16, len - 1 - i);
} else {
res += Integer.valueOf(str.charAt(i) - '0') * Math.pow(16, len - 1 - i);
}
}
}
System.out.println(res);
}
}