C++狼找兔司演必孩了子问题
的有关信息介绍如下:问题补充说明:狼找兔子问题:一座山周围有n个洞,顺时针编号为0,1,2,3,4,…,n-1。一只狼从0号洞开始,顺时针计数,每当经过第m个洞时,就进洞找兔子。例如n=5,m=3,狼经过的洞依次为0,3,1,4,2,0.输入m,n。试问兔子有没有幸免的机会?如果有该藏在哪儿?
#include<iostream>
usingnamespacestd;
intmain()
{
intn,m,i,c;
intj=0,k=0;
i360问答nta[50],b[50];
cout<<"请输入山周围的洞口总数:";
cin>>n;
cout<<endl<<"请输入狼每次经过洞口的个数:";
cin>>m;
cout<<endl<<"洞口号码依次为:";
for(i=0;i<n;i++)
{
a余必[i]=i;
cout<<a[i受袁练优光提目亲规验]<<"";
}
cout<<endl<<e点简穿争王息呼调观儿龙ndl<<"狼依次经过的洞口号码为:0";
while(c!=0)
{
k+=m;
c=k%n;
b[c]=c;
j++;
肥日念破友滑磁五两球cout<<b[c]<<"";
}
if(j==n)
cout<<endl<<endl<<"兔子没有幸免的机会"<<endl;
else
{
cout<<endl<<endl<<"兔子有幸免的机会"<<endl;
for(i=0;i<n;i++)
if(b[i]!=a[临应术皮晚右重岁元百利i])
cout<<endl<<"兔新钢南杂子可以藏在"<<i<<"洞口中"<<endl;
}
return0;
}