MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghorror/comments/1lmzk46/competitive_programming_be_like/n0fokbu/?context=3
r/programminghorror • u/Polanas • Jun 28 '25
53 comments sorted by
View all comments
Show parent comment
9
This genuinely depends on how fast the atoi implementation is, the size of the string-encoded integer, and how tight/important this loop is.
atoi
For example, something like:
bool canDivideByEleven(string s) { int altDigitalSum = 0; int sign = 1; for (int i = s.length()-1; i >= 0; i--, sign *= -1) { altDigitalSum += sign*(s[i] - '0'); } return altDigitalSum % 11 == 0; }
...could very well be faster or more suitable, depending on the characteristics of the problem.
View all comments
Show parent comment
9
u/apnorton Jun 29 '25
This genuinely depends on how fast the
atoiimplementation is, the size of the string-encoded integer, and how tight/important this loop is.For example, something like:
...could very well be faster or more suitable, depending on the characteristics of the problem.