dang7rickroll's blog

By dang7rickroll, history, 3 years ago, In English

if you are reading this blog, hi.

I have some problems with the "Div. 7" problem:

Here is the official code (from BledDest):

Code

And here is my c++ code when I try to translate from Python $$$\rightarrow$$$ C++:

Code

But, when I submit my C++ code, it gets the wrong answer on test 2 (on test case 52), you can check: 145516095

If you understand the reason why you can comment under this blog. Thank you very much for your help!

  • Vote: I like it
  • +2
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it +3 Vote: I do not like it

If you want to know the difference between your code and the python one then the difference is that the python one runs from 0 to 9(NOT INCLUDING 10) but yours does include 10 . I think that would fix your problem.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Your code runs for j from 0 to 10 so for example if n==61 then your code will check for 60%7==0, 61%7==0, 62%7==0 and so on till 70%7==0. Now you want the answer to be 63 but since you don't have a break statement at 70 it will it is divisible by 7 so it will update res to be 70 and therefore you might get WA.

So in short to correct your code you can just run for j from 0 to 9