Codeforces и Polygon могут быть недоступны в период с 6 декабря, 22:00 (МСК) по 7 декабря, 00:00 (МСК) в связи с проведением технических работ. ×

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

Автор areke, история, 9 лет назад, По-английски

Hi everyone!

I'm having trouble with my submission for problem 382A.

The lines in question are commented in the submission above, but I'll highlight them here as well for clarity.

Using the following passes all the test cases:

    long long len = w2.length();
    len -= w1.length();
    len = absol(len-1);

While using this instead fails the first one, but returns the correct answer on my local machine:

    long long len = absol(w2.length()- w1.length()-1);

Does anyone have an idea of what's going on at a technical level?

My best guess is that it has something to do with precedence, and that in the second case the function address is being returned instead of the actual length. I'm not sure if this is the problem though and I've never run into something like this before.

I've tried doing a bunch of research on this issue, but haven't yet been able to find the answer. I'm hoping the great Codeforces community can help me out!

Thank you guys in advance!

Теги c++
  • Проголосовать: нравится
  • -3
  • Проголосовать: не нравится

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

string::length returns an unsigned value, so when subtracting a larger value from a smaller one it will be large and positive instead of negative.