I was coding for a particular problem whose time limit was 2 seconds.. The no. of input was max 300000. Simply taking in the number using cin and outputting the same number with cout will take more than 2 seconds.
Any ideas on how to increase efficiency??
catchmrbharath 0 Light Poster
Recommended Answers
Jump to PostSimple, Use file I./O.
Or you can also use the input redirection operator '<' while calling the program from the command prompt$ myprogram.exe < input_data.txt
Jump to Post>I tried using scanf and printf but still wont happen in 2 seconds
I told you to use file I/O. Use fopen fread.
By the way this is a C++ forum and not a C forum. We usually don't understand printf and scanf.
Jump to Post>By the way this is a C++ forum and not a C forum.
Yes, yes it is. But printf and scanf are a part of C++ as well. It's not uncommon to drop down to stdio when iostreams are too slow.>We usually don't understand printf and scanf.
Speak …
Jump to Post>Yes, yes it is. But printf and scanf are a part of C++ as well. It's not uncommon to >drop down to stdio when iostreams are too slow.
I don't know what made me type that but I think I was in illusion that the OP has posted some C …
Jump to Post>I don't think the standards says anything about iostream being slower?
The standard doesn't make many performance guarantees. However, while iostreams offer the potential for being faster than stdio, I haven't seen any implementations that take advantage of that. The result is that iostreams are often quite a bit slower …
All 18 Replies
ArkM 1,090 Postaholic
s_sridhar 7 Junior Poster
siddhant3s 1,429 Practically a Posting Shark
ArkM 1,090 Postaholic
tux4life 2,072 Postaholic
catchmrbharath 0 Light Poster
ArkM 1,090 Postaholic
lss123 19 Newbie Poster
siddhant3s 1,429 Practically a Posting Shark
Narue 5,707 Bad Cop Team Colleague
siddhant3s 1,429 Practically a Posting Shark
Narue 5,707 Bad Cop Team Colleague
ArkM 1,090 Postaholic
catchmrbharath 0 Light Poster
ArkM 1,090 Postaholic
MosaicFuneral 812 Nearly a Posting Virtuoso
s_sridhar 7 Junior Poster
s_sridhar 7 Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.