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
人生在于攀登! 阅读(474)
评论(0) 编辑 收藏 引用