Naithani's blog

By Naithani, history, 4 years ago, In English

I was solving a problem on LightOj, my solution was correct but the problem was in the std::cout, then I replaced it to printf, then It worked fine. Plz anyone reply, why this happened.

solution without cout: link

Thanks in advance :)

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

»
4 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Your submissions are inaccessible because LightOJ isn't letting me view them. Could you post your code here in a spoiler? In any case, I'm pretty sure changing just printf to cout is not the only cause of RTE.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Fixed, i deleted one link, both code are same only difference is with printf & cout.

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

Can you post the code in a spoiler?

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

Auto comment: topic has been updated by Naithani (previous revision, new revision, compare).

»
4 years ago, # |
  Vote: I like it +8 Vote: I do not like it

I guess you mixed printf with std::cout having sync_with_stdio(false) called.

  • »
    »
    4 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Nops, I have tried approx all combo, remove/ included, that's why it causes me 20+ runtime errors... I can't think of this could happen. I think there is something weird with the lightOj C++ compiler may be old or something else.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Does using cout in both main() and solve() work?

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        cout using in main() does not give me run time error, but in solve() it gives run time error. I did not check the whole solution in main().

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Now I tried, without using solve() and I wrote all the content in main() but still go run time error.

          • »
            »
            »
            »
            »
            »
            4 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Try your solution with cout but without ios_base::sync_with_stdio(false); cin.tie(nullptr);.