### div24ever's blog

By div24ever, history, 4 years ago, ,

How to take fast I/O in C++? I am solving a problem where number of test cases can be 10^6 so i guess fast I/O will help to speed up my solution.

• -6

 » 4 years ago, # |   +3
•  » » 4 years ago, # ^ |   +3 +1 but sometimes it's not enoughAnother possible way is to implement your own reader for integer/real/signed types using getchar(): int next_int() { char c; do { c = getchar(); } while( c != '-' && !isdigit(c) ); bool neg = (c == '-'); int result = neg ? 0 : c - '0'; while( isdigit(c = getchar()) ) result = 10 * result + (c - '0'); return neg ? -result : result; } In most cases coders use it to get top1 by execution time)) But in case N = 10^6 it may be useful to beat TL with solution that wasn't intended by jury.
•  » » » 4 years ago, # ^ |   0 Thanks it did reduce my time but still TLE. I guess i have to improve my algo.
 » 4 years ago, # |   0 I got TLE in Educational Round 1 D because of cin/cout :( After contest I submitted with printf and got AC.I should have used cin tie.
 » 4 years ago, # |   0 fread + buffer could be very fast , take a look at my code (i used it in spoj many times) http://ideone.com/461DPt