I tried many times but i keep getting "wrong answer" ...please tell me what is it wrong...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include<iostream>
#include<fstream>
using namespace std;
ifstream in("data.in");
ofstream out("data.out");
int clen(unsigned long n)
{
if(n==1)
return 1;
else if(!n)
return 0;
if(!(n%2))
return clen(n/2)+1;
else
return clen(3*n+1)+1;
}
int main()
{
unsigned long i,j,k,temp,max=0;
bool ok=1;
while(in>>i&&in>>j)
{
if(i>j)
{
temp=i;
i=j;
j=temp;
ok=0;
}
max=0;
for(k=i;k<=j;k++)
if(max<clen(k))
{
max=clen(k);
}
if(ok)
out<<i<<' '<<j<<' '<<max<<endl;
else out<<j<<' '<<i<<' '<<max<<endl;
}
return 0;
}
|
http://uva.onlinejudge.org/external/1/100.pdf
Last edited on
Well just ran your code and the output is correct. You sure you have "data.in" file in the correct directory and it is named correctly?
yeah...it works perfectly for me too but despite that, it keeps getting rejected and it's becoming annoying
Last edited on
Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include<iostream>
#include<fstream>
using namespace std;
unsigned long clen(unsigned long n)
{
if(n==1)
return 1;
if(!(n%2))
return clen(n/2)+1;
else
return clen(3*n+1)+1;
}
int main()
{
unsigned long i,j,k,temp,max=0;
while(cin>>i>>j)
{
if(i>j)
{
temp=i;
i=j;
j=temp;
}
max=0;
for(k=i;k<=j;k++)
if(max<clen(k))
{
max=clen(k);
}
cout<<i<<' '<<j<<' '<<max<<endl;
}
return 0;
}
|
@ne555 yeah now i found that i shouldn't be using files but i am still getting
"wrong answer"
Also i fixed the 'ok' part :)
Last edited on
lol wtf i'm dumb
the problem was in fact that i was not resetting the 'ok' as you have pointed out earlier
it finally got accepted :)
ty a lot
Last edited on
Does your output have an extra line at the end of it?