I_m_sfg's blog

By I_m_sfg, history, 16 months ago, In English

--if the question constraints is 10^18 and input is given in digit then never use stoi,atoi,or any kind of string into digit number because it gives always tle.

--Never Use stoi,atoi with to_string it also give tle .I wasted 1 hr to solve this problem.......so don't do that...and

Happy journey to _____ to master.

  • Vote: I like it
  • +10
  • Vote: I do not like it

»
16 months ago, # |
Rev. 2   Vote: I like it +19 Vote: I do not like it

No. The function atoi itself will work fast. However, instead of the 64-bit number $$$n$$$ it will return some 32-bit number which won't be equal to the correct result if $$$n$$$ is far enough from $$$0$$$. Most of compilers will return $$$n$$$'s 32 trailing bits: https://godbolt.org/z/47eox791n. I guess it's non-standard, it is just how it is implemented.

However, I was able to find a compiler which instead returned std::numeric_limits<int32_t>::max(), it is also demonstrated in Godbolt.