题解 | #进制转换#
进制转换
http://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
fun2();
}
public static void fun2(){
Scanner sc = new Scanner(System.in);
while(sc.hasNextLine()){
String s = sc.nextLine();
System.out.println(Integer.parseInt(s.substring(2),16));
}
}
public static void fun1(){
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
String substring = s.substring(2);
HashMap<String, Integer> stringInteger = new HashMap<>();
for (int i=0;i<16;i++){
if (i<10) {
stringInteger.put(String.valueOf(i),i);
}else {
String str[] = {"A","B","C","D","E","F"};
stringInteger.put(str[i-10],i);
}
}
double sum=0;
int index = 0;
for (int j=substring.length()-1;j>=0;j--){
String key = String.valueOf(substring.charAt(j));
Integer integer = stringInteger.get(key);
int value = integer.intValue();
sum+=value*Math.pow(16,index);
index++;
}
System.out.println((int)sum);
}
}