Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
129480 | 常钰杰 | 十六进制转十进制 | C++ | Accepted | 1 MS | 272 KB | 913 | 2025-08-26 15:50:07 |
#include<bits/stdc++.h> using namespace std; long long shu(string s) { int l = s.size(); int a[l] = {}; for(int i = 0; i < l; i++) { switch(s[i]) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': a[i] = s[i] - '0'; break; case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': a[i] = s[i] - 'a' + 10; } } long long ans = 0; for(int i = l - 1, k = 1; i >= 0; i--, k *= 16) { ans = ans + (a[i] * k); } return ans; } int main() { string s; cin >> s; cout << shu(s); return 0; }