showvike's blog

By showvike, history, 4 years ago, In English

see this link: https://codeforces.com/contest/1284/submission/68190516

ios_base :: sync_with_stdio(false); cin.tie(NULL);

when remove this two line it got ac.. but before wa.. why and how??

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

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

Do you need to use iosbase hacks? scanf is fast enough without them.

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

    in c++ the string datatype.. is there any away to input and output with scanf and printf??

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

If you use

ios_base::sync_with_stdio(false);

You should not use scanf/printf, cin/cout at the same time. Or you can submit code on Visual C++

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

cin and cout are synced to stdin and stdout by default, so that people can use both C I/O and C++ I/O at the same time. You disabled it with ios_base::sync_with_stdio(false), so there are now two separate buffers which messes things up. This is why you don't write code which you don't understand. ios_base::sync_with_stdio(false) disables syncing between cin/cout and scanf/printf, and cin.tie(nullptr) disables cout being flushed automatically when you do stuff with cin. They're not magic lines of code that speeds everything up.

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

    thanks!!

    and i use cin.tie(0) or cout.tie(0) or both??

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

      cout.tie(nullptr) doesn't do anything as far as I know.