I've been writing a program operating on some stdin
data a viatal and basically the last part of which is a for / while
loop that causes a slight but totally unaccountable problem.
The thing is that even though it gives a good answer and simply works perfectly well on i.e. on idone.com
it gives a bug on my Visual Studio or on spoj.com
. The bug is that after I paste some data to my console (in my VS) there's no output until I give a letter or any other non-white sign and press enter. The output (correct of course) doesn't shows until then. As it goes about spoj.com
I see an error information that the time limit has been exceeded but I'm pretty sure that the problem is the same - for some reason the program is listening for one more sign.
So if the sign doesn't directly influence the output, why do I have to put any sign and click enter
to show the answer? I'm still far from being a pro programer so I'll really appreciate any help from You Guys.
Thanks in advance!
(...)
for (int i = 0; i < numberOfOperations; i++)
{
scanf("%d%d", &leftSetRowNr, &rightSetRowNr);
char n;
n = getchar();
if((currentSum %2) == 0)
{
copyToMainTab(resultTab, mainTab,leftSetRowNr, mainTabCurrentInd);
}
else if (currentSum%2 != 0)
{
copyToMainTab(resultTab, mainTab,rightSetRowNr, mainTabCurrentInd);
}
quickSort(mainTab, 0, (mainTabCurrentInd-1) );
if(mainTabCurrentInd > trimNumber)
{
mainTabCurrentInd = trimNumber;
}
int tempSum = 0;
for(int s = 0; s < mainTabCurrentInd; s++)
{
tempSum += mainTab[s];
}
currentSum = tempSum;
}
int nrOfEl = 1;
int nr = mainTab[0];
for (int i = 1; i < trimNumber; i++)
{
if (nr != mainTab[i])
{
nrOfEl ++;
nr = mainTab[i];
}
}
printf("%d %d", currentSum, nrOfEl);
return 0;
} (...)