Help me with this TLE please...

I don’t know why I’m getting TLE for this code :
http://www.codechef.com/viewsolution/6605888

So, I try the other way, then I got Wrong Answer :
http://www.codechef.com/viewsolution/6606308

Help me please…

Your solutions are not accessible to others as they are part of an ongoing contest. So those links are useless and will remain useless until the contest ends ( in over 900 days )

But still, the problems in the Workshop for Beginners are realyy simple, but the TLE can get new users confused.

Your first code is an infinite loop, thereby, it is receiving TLE ( while( 1 ) is the infinite loop, and you are not exiting from it )

The problem with your second code is that it checks whether scanf() returns 1, which is not the what you should be checking for.

From man ( this is the return type of scanf() )

These functions return the number of
input items assigned. This can be
fewer than provided for, or even zero,
in the event of a matching fail- ure.
Zero indicates that, although there
was input available, no conver- sions
were assigned; typically this is due
to an invalid input character, such as
an alphabetic character for a `%d’
conversion.

The value EOF is returned
if an input failure occurs before any
conversion such as an end- of-file
occurs. If an error or end-of-file
occurs after conversion has begun, the
number of conversions which were
successfully completed is returned.

That should help you understand the error. Your

while( ( scanf("%d%d%d",&a,&b,&c)  == 1)

checks if scanf() returns 1, which is not what it is supposed to return when 3 numbers are assigned.
You should change it to

while( ( scanf("%d%d%d",&a,&b,&c)  == 3)

and also change your last printf() to

printf("%d\n",max);
           ^
           you need a `\n` here, or your output will fail.

Well, those are the errors that I saw

So I submitted your code ( after applying these edits ) and it gave me an AC.

This is the


(http://www.codechef.com/viewsolution/6608494) , but it is best if you try to do it yourself and if you still fail, then check the code ( that way, you will understand all of this even better )

This is my first code :

#include <stdio.h>
int main()

{
int a,b,c,max;
while (1) {
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    max = a;
    if (b>a)
        max = b;
    if (c>max)
        max = c;
    printf("%d\n",max);
}
return 0;
}

This is the second one :

#include <stdio.h>
int main()

{
int a,b,c,max;
while(scanf("%d%d%d",&a,&b,&c)==1)
{
    max = a;
    if (b>max)
        max = b;
    if (c>max)
        max = c;
    printf("%d",max);
}
return 0;
}

Thanks mate, it works. LoL…