Codeforces and Polygon may be unavailable from December 6, 19:00 (UTC) to December 6, 21:00 (UTC) due to technical maintenance. ×

areke's blog

By areke, history, 9 years ago, In English

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!

Tags c++
  • Vote: I like it
  • -3
  • Vote: I do not like it

»
9 years ago, # |
  Vote: I like it +6 Vote: I do not like it

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.