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

Автор kunaljain, 14 лет назад, По-английски
I tried to solve Beta Round #1 - Problem A

I tried the I/O using scanf and printf. Using "%lld". But it gave a wrong answer the first test case.

While running the same code with I/O using cin and cout. It got Accepted. I could not make out what is wrong with scanning the input using scanf and printf.
I haven't seen anything such thing occur on any other judge.

Can somebody throw a light on what actually is the problem ?
  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

14 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
In Wiindows version of g++(MinGW) you should use %I64d not %lld for reading and writing long longs.
»
12 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Maybe cin and cout are better.

  • »
    »
    12 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +7 Проголосовать: не нравится

    But sometimes they are so sloooooow. std::sync_with_stdio(0); treats it.

    • »
      »
      »
      12 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Actually, using the above trick makes cin faster than scanf, and cout is faster than printf unless you use endl, the reason is that endl flushes the output buffer. Use cout << something << '\n' instead.

      • »
        »
        »
        »
        12 лет назад, # ^ |
          Проголосовать: нравится +3 Проголосовать: не нравится

        In theory — yes, because the cin/cout operators know the target type at compile time. But in practice your mileage may vary and depends on the compiler and the standard library. A few years ago I conducted extensive testing on this matter and found that sometimes iostreams was faster and sometimes it was not. But the difference was not so great, so, in my opinion, one is safe to use iostreams (with sync_with_stdio(false)).