Please run my program on your computer and tell me what is wrong and how could I correct it
I submitted my solution and the judge replied :
Your program output is greater (4231168 bytes) than the maximum
allowed for any problem by this judge (4194304 bytes).
You must interprete this as a Wrong Answer (in fact, is wrong!).
By some reason your program is writing an unlimited output.
My program:
#include<stdio.h>
#include<stdlib.h>
int maxlenij(int i,int j);
int len(int u);
main()
{ int t,i,j;
for(t=1;;++t)/* t = no. of pairs */
{
scanf("%d",&i);
if( i>0 && i<= 10000)
{ scanf("%d",&j);
printf(" %3d %3d %3d\n",i,j,maxlenij(i,j) );
}
else
break;
}
}
int maxlenij(int i,int j)/* gives maximum cycle length for integers between and including i and j */
{int t=0,h,Clen,u;
if(j/2 > i)
{ Clen = len(j/2);/* It will give max Cycle Length after the end of the loop */
for(u=j/2+1;u<=j;u++)
{
if( (u-1)/3 >=i && (u-1)%3 == 0 )
continue;
h = len(u);
if( h > Clen)
Clen = h;
}
}
else
{ Clen = len(i);/* It will give max Cycle Length after the end of the loop */
for(u=i+1;u<=j;u++)
{ h = len(u);
if( h > Clen)
Clen = h;
}
}
return(Clen);
}
int len(int u)
{
if(u == 1)
{
return(1);
}
else if( u % 2 == 1)
{
u = 3*u + 1;
return(1 + len(u) );
}
else
{ u = u/2;
return(1 + len(u) );
}
}
#include<stdio.h>
#include<stdlib.h>
int maxlenij(int i,int j);
int len(int u);
main()
{ int t,i,j;
for(t=1;;++t)/* t = no. of pairs */
{
scanf("%d",&i);
if( i>0 && i<= 10000)
{ scanf("%d",&j);
printf(" %3d %3d %3d\n",i,j,maxlenij(i,j) );
}
else
break;
}
}
int maxlenij(int i,int j)/* gives maximum cycle length for integers between and including i and j */
{int t=0,h,Clen,u;
if(j/2 > i)
{ Clen = len(j/2);/* It will give max Cycle Length after the end of the loop */
for(u=j/2+1;u<=j;u++)
{
if( (u-1)/3 >=i && (u-1)%3 == 0 )
continue;
h = len(u);
if( h > Clen)
Clen = h;
}
}
else
{ Clen = len(i);/* It will give max Cycle Length after the end of the loop */
for(u=i+1;u<=j;u++)
{ h = len(u);
if( h > Clen)
Clen = h;
}
}
return(Clen);
}
int len(int u)
{
if(u == 1)
{
return(1);
}
else if( u % 2 == 1)
{
u = 3*u + 1;
return(1 + len(u) );
}
else
{ u = u/2;
return(1 + len(u) );
}
}
Ok, I commented out the text... and judge still doesnt like it! Here is the updated code:
[cpp]//judge@uva.es
//@JUDGE_ID: 20308JC 100 C++
//@BEGIN_OF_SOURCE_CODE
#include <iostream.h>
int maxcycle(int n)
{
int count = 1;
while(n != 1)
{
if(n % 2)
n = 3 * n + 1;
else
n = n / 2;
count++;
}
return count;
}
int main()
{
int start = 0;
int end = 0;
int temp = 0;
int largest = 0;
// cout << "Please enter 2 integers separated by a space or a new line:\n";
cin >> start;
cin >> end;
if(start > 0 && start < 10000 && end > 0 && end < 10000)
{
cout << start << " " << end << " ";
The program will not jump to the else case. In other words, it loop infinitely.
Try to take a look at the return value of scanf.
Hope can help~
p.s. try don't post the code directly, and on the other hand, ask for hint and advice is a better approach to solve the problems, at least to me. Since it's not so good to ask the other to debug for you.
Btw, your first posted program *did* make the main() call at the end. Please explain how the judge could tell you a time of 0.000 back then and now it would run forever. I don't understand.
alright, i lied judge says this for the first code:
Dear Dragoon:
Your program output is greater (4236247 bytes) than the maximum
allowed for any problem by this judge (4194304 bytes).
You must interprete this as a Wrong Answer (in fact, is wrong!).
By some reason your program is writing an unlimited output.
EOF means end of file ... and that means when u reach the end of a file hehe
generally is the form i use to check the end of the input (there are some execptions)
cause generally i use and i think the judge uses too , redirecting files to the input of the
program...