Weird Behavior Automated Inputs vs Custom Input

The issue occurs for this question:

My code was running locally just fine but I always do a test run on the CodeChef IDE(CodeChef: Practical coding for everyone) before submitting. I found out that I was getting a SIGCONT error. I also found out that my code works on custom inputs but throws an error on the automated sample inputs. So I tried to take the automated values and print them. I stumbled upon this issue:
I tried running this code on the CC’s submission IDE:

    #include <bits/stdc++.h> 
    using namespace std;
    int main(){  
      int t;
      cin>>t;
      cout<<t<<endl;
      }

Output:
0
ScreenShot


After that, I introduced a while loop(see the code below):

  #include <bits/stdc++.h>
   using namespace std;
    int main(){  
      int t;
      cin>>t;
      cout<<t<<endl;    
      while(t--)
        cout<<t<<endl;
      }

Output(a garbage value):
11040
11039
11038
11037
11036
11035
11034

I have a few questions:

  • Why don’t I get the t that was specified in the sample input of the question i.e 5?

  • Why was the input t different both times? Without the loop, the STDIN gives me a 0 and with loop some garbage value. This happens every time for this question.

1 Like

You are supposed to provide input yourself
it won’t from prob automatically
check that box beside custom input (see the img)
then paste whatever you what to give as input
so when you read something (cin in ur case) it will read from custom inputs

1 Like

@ganesh92 Thanks for the reply. I am aware of the custom inputs. But I am confused now. In all of my previous questions, I never used custom inputs. How were they running then?

1 Like

AFAIK there are no automated sample inputs. You have to feed them in Custom Input section yourself.

2 Likes

So this screenshot is for a different question:


In this case, I didn’t supply Custom Inputs. I had always assumed that “Successfully executed” meant that it took the sample input case from the problem. My bad, but then again, why this code results in “Successfully executed” and the code above(in my first post) gives me a garbage value. What does Successfully executed imply here?
@vijju123 Thanks!

1 Like

Hey,

Successfully executed means the code ran - nothing else. If you dont supply input, it may result in undefined behavior or variables taking garbage values. The result may change from “Sucessfully Executed” to Runtime errors to TLE etc depending on time and state of server/judge when you compile.

2 Likes