X-O__O-X's blog

By X-O__O-X, history, 20 months ago, In English

I have two solutions first, second for this problem You probably don't have to read all of this. The two solutions are identical except for the following:

I got wrong answer in one case: when I invoke function PLAY() and use cout like this

cout << "Impossible.\n";

but when I use cout but not call PLAY() or use printf(), answer is accepted.

void PLAY()
	cin.tie(0), cout.tie(0);

Any explanations ?

  • Vote: I like it
  • 0
  • Vote: I do not like it

20 months ago, # |
  Vote: I like it 0 Vote: I do not like it

It looks to me that you are using both cout and printf. If you set sync with stdio to false, then the order of couts and printfs might be out of order. Check https://en.cppreference.com/w/cpp/io/ios_base/sync_with_stdio they have an example there that matches what would happen to you.

So only using printfs would work since printf retains its own order. Not calling that function also works since you dont set that flag to false, so cout and printf will keep order between them.