lundi 5 septembre 2016

Segmentation fault, iterators by value suspected

I'm just trying to have a little fun solving this Hackerrank problem: http://ift.tt/2bOywvX

I managed to solve it like this: http://ift.tt/2bOdk4s, excuse the debugging code.

Then I went on and tried to use iterators instead of [] access. Here it is: http://ift.tt/2bOy0y9 It also runs and passes all test cases in Hackerrank.

But! In this latest cases it gives me a "Segmentation fault: 11" when I run it locally in my computer (Mac OS X El Capitan 10.11.6). I compile with:

clang++ -std=c++11 -stdlib=libc++ -Wno-c++98-compat-pedantic -Wno-c++98-compat nikita-and-the-game.cc -o nikita

I suspect the problem is in the const_iterators I pass by value to the recursive function, however I tried passing them by reference and run into the same problem. Anyone got any idea about what is going on? (Or should I just let it go :P)

PS: available in github http://ift.tt/2bOetsO

PS2: On a side note, I'm using softabs with 4 spaces while editing this with TextMate 2 on my computer but keep seeing the code badly formatted in github. Anyone has run into this before?

Aucun commentaire:

Enregistrer un commentaire