there are lots of problems on SPOJ that require input must be taken from an input file. Those types of problems require that you get input till the end of input file and you cant use simple while or for loop to get input say 'n' no of times or until a particular number is entered. i tried so many things like finding EOF or checking for (!scanf()) but none of them worked and finally i had to keep my working codes for those problems aside since if i cant take inputs as described i will either get Time limit exceeded or runtime error.
after a long searching of such code i finally got perhaps the easiest way to get around that problem of getting input. it is damn simple. all you need to do is to make an object(e.g. string s;) of string type in CPP of course and then simply initialize a loop as
string s;
while(getline(cin,s))
{
use s as you wish
print result
}
that was a normal code but if you dont know this in prior then you cant do anything since it is not very common code. few examples of those problems which require this type of implementation are encondin, javac, bishops
Sunday, September 14, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment