intmain() { string s; for (; getline(cin, s); ) { int res = 0; for (int i = 2, n = s.size(); i < n; i++) { char c = s[i]; int x = isdigit(c) ? c - '0' : hashmap[c]; res = res * 16 + x; } cout << res << endl; } return0; }
publicclassMain{ publicstaticvoidmain(String[] args){ Map<Character, Integer> hash = new HashMap<>(); hash.put('A', 10); hash.put('B', 11); hash.put('C', 12); hash.put('D', 13); hash.put('E', 14); hash.put('F', 15); Scanner in = new Scanner(System.in); for (; in.hasNext();) { String s = in.next(); char[] chs = s.toCharArray(); int res = 0; for (int i = 2, n = s.length(); i < n; i++) { char c = chs[i]; int x = Character.isDigit(c) ? c - '0' : hash.get(c); res = res * 16 + x; } System.out.println(res); } } }