题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
#include <iostream> using namespace std; int main() { string A; cin >> A; A = A.substr(2); int num{}; auto lam = [](char a) { int tmp = static_cast<int>(a); int zero = static_cast<int>('0'); int A = static_cast<int>('A'); if (tmp >= A) return 10 + tmp - A; else return tmp - zero; }; for (auto v : A) { num += lam(v); num*=16; } cout << num / 16; } // 64 位输出请用 printf("%lld")
题目很简单。刚刚学了lambda表达式,尝试用一下