import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuilder sb = new StringBuilder(sc.nextLine());
int n = sb.length();
long sum = 0;
int i = 0;
while (i < n) {
char c = sb.charAt(n - 1 - i);
long k = (long) Math.pow(16, i);
switch (c) {
case '0':
break;
case '1':
sum += k;
break;
case '2':
sum += 2 * k;
break;
case '3':
sum += 3 * k;
break;
case '4':
sum += 4 * k;
break;
case '5':
sum += 5 * k;
break;
case '6':
sum += 6 * k;
break;
case '7':
sum += 7 * k;
break;
case '8':
sum += 8 * k;
break;
case '9':
sum += 9 * k;
break;
case 'A':
sum += 10 * k;
break;
case 'B':
sum += 11 * k;
break;
case 'C':
sum += 12 * k;
break;
case 'D':
sum += 13 * k;
break;
case 'E':
sum += 14 * k;
break;
case 'F':
sum += 15 * k;
break;
}
i++;
}
System.out.println(sum);
}
}
蓝桥杯 基础练习 十六进制转十进制 JAVA
最新推荐文章于 2021-04-17 09:27:12 发布