题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str=in.nextLine().substring(2);
int total=0;
Map<Character,Integer> hs=new HashMap<>();
hs.put('0',0);
hs.put('1',1);
hs.put('2',2);
hs.put('3',3);
hs.put('4',4);
hs.put('5',5);
hs.put('6',6);
hs.put('7',7);
hs.put('8',8);
hs.put('9',9);
hs.put('A',10);
hs.put('B',11);
hs.put('C',12);
hs.put('D',13);
hs.put('E',14);
hs.put('F',15);
for(int i=str.length()-1,j=0;i>=0;i--,j++){
total+=hs.get(str.charAt(i))*(int)Math.pow(16,j);
}
System.out.println(total);
}
}
查看25道真题和解析