I am getting a very strange bug in my code for today's round problems B1, 2.
At a moment, I'm having a set of pairs.
[s]: {(1, 1), (1, 4), (1, 5), (1, 9), (1, 10), (2, 2), (2, 7)}
Then I'm accessing the last and second last element. (line 51-54 in mycode)
it = s.rbegin(); // prints *it = (2, 7)
it--;
// prints *it = (1, 10)
But for some weird reason it jumps off (2, 2) and I'm unable to figure out why.
Any help will be appreciated.
Since
it
is a reverse iterator,it++
should yield the second last element instead, andit--
will make it invalid, and dereferencing that is UB.Thanks, it worked.