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

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

556A - Case of the Zeros and Ones

HERE is my code:

it fails on test 12. the input is not totally visible since its a long no. the output to test 12 should have been 0(according to the site) but am getting the output as 199996

Теги 900
  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

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

Auto comment: topic has been updated by zonedout (previous revision, new revision, compare).

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

Auto comment: topic has been updated by zonedout (previous revision, new revision, compare).

»
47 часов назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

i don't know about your approach but i think the difference of the number of 0s and 1s in the string solves the problem (as you can always eliminate one 1 and one 0 from the string so remaining extra will be the ans)

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

Try to solve it using stack. Here's my solution:SOL

»
33 часа назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

I think you are using std::string::erase wrongly. Please read some documentations if you are unsure of what you do.

In your specific case, I'm understanding that you want to erase index i and i+1; in which case, the correct call should be str.erase(i, 2) instead of str.erase(i, i+1).