Hi, im a complete noob in cpp and did this problem 540A - Кодовый замок
Here is my submission: 119121702
The test case that the code fails is
12
102021090898
010212908089
The code works perfectly on my pc but when i upload it to codeforces i get a runtime error and i cant figure out why. Any help would be appreciated...
Thanks in advance.
stol
tries to convert tolong
.Type
long
is depended on machine and compiler. Maybe on your env it is 64-byte, when in CF it is 32 byte.But in your problem there up to 1000 digits there is no integer type that can hold numbers like that. So your solution is not correct in general
Yup, that is pretty much the problem.
What you can do instead, is just use indexing. You can access a single character of any string using same way as you access array's elements
state_orig[i]
(Think string as an array of chars, and indexing will return a character).Another quality of life recommendation would be to use
state_orig.pop_back()
instead ofstate_orig.erase(state_orig.length() - 1)
. Both will do the same thing, but it is easier to understand, and is more cleaner.Thank you so much. You were very helpful. I did it correctly this time. 119140129