能力值:
( LV4,RANK:45 )
|
-
-
2 楼
自己实现一个不就完了,网上符合你要求的代码多的是 改编自牛客网 #include<cstdio> using namespace std; int isAlpha(char num) { return (num >= 'A' && num <= 'Z') || (num >= 'a' && num <= 'z'); } int isDigit(char num) { return num >= '0' && num <= '9'; } char toLower(char num) { char result = num; if (num >= 'A' && num <= 'Z') result += 32; return result; } long long strtoLL(const char *num_str, char **endptr, int base) { long long result = 0; long long value; int tmpbase=0; if (*num_str == '0') { num_str++; if (*num_str == 'x' || *num_str == 'X') { tmpbase = 16; num_str++; } else tmpbase = 8; } else tmpbase = 10; if(base)tmpbase=base; while (true) { if (isAlpha(*num_str) || isDigit(*num_str)) { value = isAlpha(*num_str) ? (toLower(*num_str) - 'a' + 10) : (*num_str - '0'); if (value >= base) break; result = result * base + value; num_str++; } else break; } if (endptr) *endptr = const_cast<char*> (num_str); return result; } long long Mystrtol(const char *num_str, char **endptr, int base) { if (*num_str == '-') return -1 * strtoLL(num_str + 1, endptr, base); else return strtoLL(num_str, endptr, base); } int main() { char *str = "0x107A2615123A8"; char *temp; long long result = Mystrtol(str, &temp,16); printf("%lld",result); return 0; }
|
能力值:
( LV9,RANK:280 )
|
-
-
3 楼
sscanf"%I64X"
|
|
|