im sorry but this thread is really long and i think it should get ride of post that really dont matter. It's extremely cumbersome going one by one to find if the question has been resolved or not.
I got WA for a program and im still confuse as to how the judge actually goes throu it, is it:
input
output
input
output
or
input
input
output
output
yes, yes it has been discussed but there's always people that says the first one others say the second one, does anyone really have a real answer?.... and how about the end of line? if you're running a program for this last case it's really possible to get an endl after the last output... if that's counted as WA then............. *sighs*
I got WA for a program and im still confuse as to how the judge actually goes throu it, is it:
input
output
input
output
or
input
input
output
output
What do you mean by this?
There's exactly one input file, which your program reads on the standard input. After your program terminates, all the output it made to the standard output will be compared with expected output file. If they are the same, you'll get AC. That's all there is about testing.
I got WA for a program and im still confuse as to how the judge actually goes throu it, is it:
input
output
input
output
or
input
input
output
output
What do you mean by this?
There's exactly one input file, which your program reads on the standard input. After your program terminates, all the output it made to the standard output will be compared with expected output file. If they are the same, you'll get AC. That's all there is about testing.
well I know what a judge does, maybe i didnt express myself correctly?
according to you the program has to read all lines before making any output? if this is the case, then each answer (which is generally one per line) has to be store in some place until all lines of input are read and then you put all your stored output.
I could've swore I read someone saying you read one line then you output the result, then you read the next line and output the next result and so on... which would make more sense to me.
EDITED: I just found out, for those of you still wondering the answer is actually alternated with the input.
It doesn't matter to the judge, whether you read all the test cases before any processing, or solve case by case.
The latter is better, because it needs less memory. (the memory is, you know, limited; 32 Mb by default)
You are printing i and j after you have swapped the values in i and j, but you are supposed to print the values of i and j in the order given in the input.
#include <iostream>
using namespace std;
void swap (unsigned long &a, unsigned long &b) {
unsigned long temp;
temp = a;
a = b;
b = temp;
}
unsigned long cycle_length (unsigned long n) {
unsigned long length=1;
do {
length++;
if (n%2!=0)
n = 3*n+1;
else
n /= 2;
} while (n!=1);
return length;
}
unsigned long max_length(unsigned long a, unsigned long b) {
unsigned long i,maxlength=0;
for (i=a;i<=b;i++) {
if (cycle_length(i)>maxlength)
maxlength=cycle_length(i);
}
return maxlength;
}
int main () {
unsigned long i,j;
while (cin >> i >> j) {
cout << i << " " << j << " ";
if (i>j)
swap (i,j);
cout << max_length(i,j) << endl;
}
return 0;
}
I can't figure out what's wrong with my code :|
I am swapping vars... I output them in correct way... :/
I'm newbie here and have to introduce myself. My name is Alex, 28 y.o. from Hungary. I have been looking for such kind of forum for a long time and at least I'm here. Hope that I'll become a member of this community and finally get the answers on all my questions, and may be my experience will be useful for all the ppl around. My Geek code QA7fMi9imv2udB.
thx emotional blind...
Ii still don't know why I usen do while instead of while do. Anyway my prog is accepted. It runs for 3.6s so now I will try to speed it up
#include <iostream>
using namespace std;
class MaxCycle
{
public:
int getMax(long i, long j);
private:
long j;
long i;
};
int MaxCycle::getMax(long i, long j)
{
long long temp = 0;
long long max = 0;
long long count = 1;
if ( i > j )
{
temp = i;
i = j;
j = temp;
}
for (int min = i; min <= j; min++)
{
count = 1;
long long answer = min;
do
{
if ( answer == 1 )
{
continue;
}
if ( answer%2 != 0 )
{
answer = (3 * answer) + 1;
}
else
{
answer = ( answer / 2 );
}
count++;
}
while ( answer != 1);
if ( count > max )
{
max = count;
}
}
return max;
}
int main ()
{
int firstNumber;
int secondNumber;
cin >> firstNumber;
cin >> secondNumber;
MaxCycle M1;
int result = M1.getMax(firstNumber,secondNumber);
cout << firstNumber;
cout << " ";
cout << secondNumber;
cout << " ";
cout << result;
cout << "\n";
return 0;
}