Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Advanced/C++/1010] Suggestion #132

Open
xwcai98 opened this issue Mar 8, 2020 · 0 comments
Open

[Advanced/C++/1010] Suggestion #132

xwcai98 opened this issue Mar 8, 2020 · 0 comments

Comments

@xwcai98
Copy link

xwcai98 commented Mar 8, 2020

问题:
在string转int64_t的时候,代码倒序计算,并使用了pow()函数。
pow()函数返回是double类型的,计算十分缓慢。
建议直接顺序处理:

auto to_num = [](char c) -> int64_t {
	if (isdigit(c)) return c - '0';
	return c - 'a' + 10;
};
int64_t res = 0;
for (auto e : str)
    res = res * radix + to_num(e);

另附的我的完整code,https://blog.csdn.net/abcdefbrhdb/article/details/104663704

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant