/* -*- coding: utf-8 -*- * * 2385.cc: No.2385 Parse Integer with Radix - yukicoder */ #include #include #include using namespace std; /* constant */ /* typedef */ typedef long long ll; /* global variables */ /* subroutines */ /* main */ int main() { int tn; scanf("%d", &tn); while (tn--) { char s[128]; scanf("%s", s); int l = strlen(s); int b = 10, st = 0; if (l > 2 && s[0] == '0' && (s[1] < '0' || s[1] > '9')) { if (s[1] == 'b') b = 2, st = 2; else if (s[1] == 'o') b = 8, st = 2; else if (s[1] == 'x') b = 16, st = 2; } ll n = 0; for (int i = st; i < l; i++) { int d = (s[i] <= '9') ? s[i] - '0' : s[i] - 'a' + 10; n = n * b + d; } printf("%lld\n", n); } return 0; }