题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // Life is short, i love JAVA. // System.out.println(Integer.valueOf(in.next().substring(2), 16)); String str = in.nextLine(); int result = 0, i = 2, len = str.length(); while (i < len) { char c = str.charAt(i++); int ch; if (c >= '0' && c <= '9') { ch = c - '0'; } else if (c >= 'a' && c <= 'z') { ch = c - 'a' + 10; } else { ch = c - 'A' + 10; } result *= 16; result += ch; } System.out.println(result); } }
#华为笔试#