题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
#include <math.h> #include <stdio.h> #include <string.h> int main(){ char hex[34] = {0}; long long s; fgets(hex, sizeof(hex), stdin); int len = strlen(hex) - 1; hex[len] = '\0'; for(int i = 2; i<len; i++){ if(hex[i]>='0' && hex[i]<='9') hex[i] = hex[i] - '0'; else if(hex[i]>='a' && hex[i]<='f') hex[i] = hex[i] - 'a' + 10; else if(hex[i]>='A' && hex[i]<='F') hex[i] = hex[i] - 'A' + 10; s += hex[i] * pow(16, len - i - 1); } printf("%d",s); return 0; }