Input/Output algorithm

Let's talk about algorithms!

Moderator: Board moderators

Input/Output algorithm

Postby michael flatley » Thu Feb 26, 2004 12:28 am

I'm working on a problem right now (specifically 10006) and I'm trying to improve my time by experimenting with various input/output routines. What I'm doing at the moment is alternating calls between gets and fwrite. This is quite fast but what I'd rather do is have one large call to fread that puts all the input into a buffer and then one call to fwrite that has access to an output buffer I've created. I've tested this alternate input method on my home machine with the following code added (and an appropriate infile...):

#ifndef ONLINE_JUDGE
freopen("infile.txt", "r", stdin);
freopen("outfile.txt", "w", stdout);
#endif

On my machine the code works just as it should with an infile covering all strange cases I can think up. However, the online judge just hangs and I get a TLE. Does the online judge REQUIRE that we alternate between inputs and outputs or have I come across something obscure?
michael flatley
New poster
 
Posts: 2
Joined: Thu Feb 26, 2004 12:16 am

Postby anupam » Thu Feb 26, 2004 7:51 am

I think the problem is in your algorithm. because, if the #ifdef didn't work, you would probably had restricted function error.
--
Anupam
"Everything should be made simple, but not always simpler"
anupam
A great helper
 
Posts: 405
Joined: Wed Aug 28, 2002 6:45 pm

Postby michael flatley » Thu Feb 26, 2004 11:29 pm

I figured it out, the input was much larger than I had assumed it would be. A larger buffer fixed the situation.
michael flatley
New poster
 
Posts: 2
Joined: Thu Feb 26, 2004 12:16 am


Return to Algorithms

Who is online

Users browsing this forum: No registered users and 1 guest