题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
import java.util.Scanner; import java.lang.Math; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String str = sc.next(); System.out.print(getChange(str)); } sc.close(); } private static int getChange(String s){ int n = 0; for(int i=0;i<s.length()-2;i++){ int num = 0; char c = s.toUpperCase().charAt(i+2); if(Character.isDigit(c)){ num = c - '0'; }else{ num = c - 'A' + 10; } n += num * Math.pow(16,s.length()-i-3); } return n; } }