You are on page 1of 3

import java.io.

;
public class CandidateCode
{
public static int passCount(int input1,int input2,int input3)
{
if( !(3 <= input1 && input1 <=1000)){
return -1;
}
if( !(3 <= input2 && input2 <=1000)){
return -1;
}
int N=input1;
int M=input2;
int L=input3;
int output=0;
int Pos=1;
int[] ternCount= new int[N];
if(N > 0 && M >0 && L>0)
{
while((ternCount[Pos-1])<M)
{
if( (++ternCount[Pos-1])!=M )
{
if(ternCount[Pos-1]%2!=0)//odd
{
Pos=MoveRight(Pos,L,N);
}
else
{
Pos=MoveLeft(Pos,L,N);
}
output++;
}
else
{
return output;
}
}
return (output);
}
else
return -1;
}
public static int MoveLeft(int cur,int moveTimes,int total )
{
int Pos = (cur+moveTimes)%total;

return Pos==0 ? total : Pos;


}
public static int MoveRight(int cur,int moveTimes,int total )
{
int Pos=(total+cur-moveTimes)%total;
return Pos==0 ? total : Pos;
}
}

You might also like