Блог пользователя yamero

Автор yamero, история, 3 года назад, По-английски

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.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

stol tries to convert to long.
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

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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 of state_orig.erase(state_orig.length() - 1). Both will do the same thing, but it is easier to understand, and is more cleaner.