Na2a's blog

By Na2a, history, 8 years ago, In English

Hello, Codeforces!

Yesterday, in CF Round 366 my friend Birjik encountered a strange problem. His correct code was receiving Runtime Error in sample case.

Take a look at these codes:
Runtime error
Accepted

As you can notice, one code has these lines:

ios_base::sync_with_stdio(0);
cin.tie(0);

Strange, isn't it?
As I have understood, this happens because of an array called read.
Renaming that array solves this problem.

Long story short, using ios_base / cin.tie receives runtime error if we have a variable named read in our code.
Be careful!

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

| Write comment?
»
8 years ago, # |
  Vote: I like it -69 Vote: I do not like it

cin/cout — зло

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +31 Vote: I do not like it

    глобальные переменные — зло

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    looks like everyone is mad at you for resigning your job :D

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

Workarounds: mark the variable static, put it into an anonymous namespace, put it into a named namespace/class, or don't use global variables.