Hi guys. I'm practicing for the CCC, a programming competition. I got stuck on a problem, so I copied the problem's answer from turing into C++. When I run my program in C++ though, I get a different answer from the one in turing. I've been spending hours trying to find the difference between the turing answer and my C++ answer, but to no avail. So basically, I'm asking what's the difference between the turing and C++ program?
Correct Answer in Turing
My wrong answer in C++.
Correct Answer in Turing
Code:
function between (a, b, c : int) : boolean
result a <= b and b <= c
end between
% this recursively tries every route to the end (7000)
procedure findPath (distance : int)
if distance = 7000 then
% made it to the end!
% One more way to get there
ways := ways + 1
put ways
else
% recursively try all motels that you can get to
for i : 1 .. size
put i
if between (minn, motel (i) - distance, maax) then
findPath (motel (i))
end if
end for
end if
end findPath
Code:
int truck(int distance)
{if (distance == 7000)
{ pos=pos+1; cout<< pos << "pos"; }
else
for (int i=1;i<=motels.size();i++)
{
cout << i;
if(minn <= motels[i] - distance && maxx >= motels[i] - distance)
{truck(motels[i]);}
}
Comment