Apr 26, 2011 at 7:29pm
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 Apr 26, 2011 at 7:44pm
Apr 26, 2011 at 10:45pm
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?
Apr 27, 2011 at 5:53am
yeah...it works perfectly for me too but despite that, it keeps getting rejected and it's becoming annoying
Last edited on Apr 27, 2011 at 5:53am
Apr 27, 2011 at 4:46pm
Last edited on Apr 27, 2011 at 5:00pm
Apr 27, 2011 at 5:22pm
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 Apr 27, 2011 at 5:24pm
Apr 27, 2011 at 7:59pm
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 Apr 27, 2011 at 8:00pm
May 6, 2011 at 6:26pm
Does your output have an extra line at the end of it?