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.