
int getNum(int a,int b,int c,int d,int e)
{
static long int num=0;
static int startPointA=a,startPiontB=b;

if (startPointA==a && startPiontB==b && num!=0)

{
return 0;
}

if ((b+d)%e==(a+c)%e)

{
return num+1;
}

else
{
num++;
return getNum((a+c)%e,(b+d)%e,c,d,e);
}
return 0;
}


int main()
{
int startPointA,startPointB,longA,longB,totalLong;
printf("請依次輸入青蛙A的起始點、青蛙B的起始點、青蛙A依次跳躍距離、青蛙B依次跳躍距離和總長度:");
scanf("%d %d %d %d %d",&startPointA,&startPointB,&longA,&longB,&totalLong);
while (startPointA==startPointB)

{
printf("你輸入數據有誤,請重新輸入:");
scanf("%d %d %d %d %d",&startPointA,&startPointB,&longA,&longB,&totalLong);
}

int num=getNum(startPointA,startPointB,longA,longB,totalLong);

if (longA==longB || num==0)

{
printf("Impossible\n");
}
else

{
printf("%d\n",num);
}

return 0;
}

posted on 2009-08-03 11:31
人生在于攀登! 閱讀(482)
評論(0) 編輯 收藏 引用