You are not logged in. Please login at www.codechef.com to post your questions!

×

scanf VS std::cin

which works faster in c++?
std::ios::sync+with_stdio(false)

std::cin

or scanf ??

asked 14 Aug, 12:02

rashi13's gravatar image

2★rashi13
313
accept rate: 0%

edited 14 Aug, 12:07


http://codeforces.com/blog/entry/5217
Give this thread a read and you will get it :)

link

answered 14 Aug, 12:10

ista2000's gravatar image

5★ista2000 ♦
2.0k318
accept rate: 20%

The difference after using fast I/O (like ios_base... , cin.tie(0), cout.tie(0), using newline char instead of endl etc.) is negligible to me. If you are still getting TLE despite having correct complexity, I think your code is "crude" and needs some hardware level optimizations. Problem setters ought not to set such strict time limits, but if they feel like testing this, or demand a refined solution instead of a "crude" one, then its good to know how to optimize your code further on such level. (I often see it on hackerrank questions - correct complexity + refined solution gets easy AC, rest get stuck on 1-2 cases)

link

answered 14 Aug, 12:28

vijju123's gravatar image

4★vijju123 ♦
11.3k1316
accept rate: 18%

edited 14 Aug, 12:29

std::ios::sync+with_stdio(false)

This does not increase speed of cout.. Point to be noted..

link

answered 14 Aug, 12:12

kauts_kanu's gravatar image

5★kauts_kanu
1.0k19
accept rate: 19%

1

Using cout.tie(0) speeds cout a bit though.

(14 Aug, 12:14) ista2000 ♦5★

thanks for the link!! quite informative as codeforces is always...

link

answered 14 Aug, 12:38

rashi13's gravatar image

2★rashi13
313
accept rate: 0%

1

Thank you :)

(14 Aug, 15:05) ista2000 ♦5★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×143
×31

question asked: 14 Aug, 12:02

question was seen: 443 times

last updated: 14 Aug, 15:05